Restore usage of slices package

This commit is contained in:
𐲓𐳛𐳪𐳂𐳐 𐲀𐳢𐳦𐳫𐳢 𐲥𐳔𐳛𐳪𐳌𐳑𐳖𐳇 2024-12-21 17:33:49 +08:00 committed by GitHub
parent db934f0832
commit de40dc2265
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 28 additions and 33 deletions

View File

@ -5,6 +5,7 @@ import (
"encoding/json"
"fmt"
"reflect"
"slices"
"strings"
cnet "github.com/xtls/xray-core/common/net"
@ -31,9 +32,6 @@ func JSONMarshalWithoutEscape(t interface{}) ([]byte, error) {
}
func marshalTypedMessage(v *cserial.TypedMessage, ignoreNullValue bool, insertTypeInfo bool) interface{} {
if v == nil {
return nil
}
tmsg, err := v.GetInstance()
if err != nil {
return nil
@ -194,29 +192,28 @@ func marshalKnownType(v interface{}, ignoreNullValue bool, insertTypeInfo bool)
}
}
var valueKinds = []reflect.Kind{
reflect.Bool,
reflect.Int,
reflect.Int8,
reflect.Int16,
reflect.Int32,
reflect.Int64,
reflect.Uint,
reflect.Uint8,
reflect.Uint16,
reflect.Uint32,
reflect.Uint64,
reflect.Uintptr,
reflect.Float32,
reflect.Float64,
reflect.Complex64,
reflect.Complex128,
reflect.String,
}
func isValueKind(kind reflect.Kind) bool {
switch kind {
case reflect.Bool,
reflect.Int,
reflect.Int8,
reflect.Int16,
reflect.Int32,
reflect.Int64,
reflect.Uint,
reflect.Uint8,
reflect.Uint16,
reflect.Uint32,
reflect.Uint64,
reflect.Uintptr,
reflect.Float32,
reflect.Float64,
reflect.Complex64,
reflect.Complex128,
reflect.String:
return true
default:
return false
}
return slices.Contains(valueKinds, kind)
}
func marshalInterface(v interface{}, ignoreNullValue bool, insertTypeInfo bool) interface{} {

View File

@ -2,6 +2,7 @@ package core
import (
"io"
"slices"
"strings"
"github.com/xtls/xray-core/common"
@ -64,14 +65,11 @@ func GetMergedConfig(args cmdarg.Arg) (string, error) {
supported := []string{"json", "yaml", "toml"}
for _, file := range args {
format := getFormat(file)
for _, s := range supported {
if s == format {
files = append(files, &ConfigSource{
Name: file,
Format: format,
})
break
}
if slices.Contains(supported, format) {
files = append(files, &ConfigSource{
Name: file,
Format: format,
})
}
}
return ConfigMergedFormFiles(files)