From 80cc0cd5db054cf534ae9a1927ae5711dd1a57b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=96=E7=95=8C?= Date: Fri, 1 Dec 2023 20:15:11 +0800 Subject: [PATCH] Migrate contentjson and badjson to library & Add omitempty in format --- cmd/sing-box/cmd_format.go | 7 +- cmd/sing-box/cmd_geoip_export.go | 2 +- cmd/sing-box/cmd_merge.go | 2 +- cmd/sing-box/cmd_rule_set_compile.go | 2 +- cmd/sing-box/cmd_rule_set_format.go | 2 +- cmd/sing-box/cmd_run.go | 4 +- common/badjson/array.go | 46 --------- common/badjson/json.go | 54 ---------- common/badjson/object.go | 79 --------------- common/badjsonmerge/merge.go | 80 --------------- common/badjsonmerge/merge_test.go | 59 ----------- common/badversion/version_json.go | 2 +- common/json/comment.go | 128 ------------------------ common/json/std.go | 18 ---- debug_http.go | 4 +- experimental/clashapi/api_meta.go | 2 +- experimental/clashapi/api_meta_group.go | 2 +- experimental/clashapi/connections.go | 2 +- experimental/clashapi/proxies.go | 2 +- experimental/clashapi/server.go | 2 +- option/config.go | 2 +- option/inbound.go | 4 +- option/json.go | 4 +- option/outbound.go | 4 +- option/platform.go | 2 +- option/rule.go | 4 +- option/rule_dns.go | 4 +- option/rule_set.go | 8 +- option/tls_acme.go | 4 +- option/types.go | 2 +- option/udp_over_tcp.go | 2 +- option/v2ray_transport.go | 4 +- route/rule_set_local.go | 2 +- route/rule_set_remote.go | 2 +- 34 files changed, 44 insertions(+), 503 deletions(-) delete mode 100644 common/badjson/array.go delete mode 100644 common/badjson/json.go delete mode 100644 common/badjson/object.go delete mode 100644 common/badjsonmerge/merge.go delete mode 100644 common/badjsonmerge/merge_test.go delete mode 100644 common/json/comment.go delete mode 100644 common/json/std.go diff --git a/cmd/sing-box/cmd_format.go b/cmd/sing-box/cmd_format.go index c5e939e4..fc47c5a8 100644 --- a/cmd/sing-box/cmd_format.go +++ b/cmd/sing-box/cmd_format.go @@ -5,9 +5,10 @@ import ( "os" "path/filepath" - "github.com/sagernet/sing-box/common/json" "github.com/sagernet/sing-box/log" E "github.com/sagernet/sing/common/exceptions" + "github.com/sagernet/sing/common/json" + "github.com/sagernet/sing/common/json/badjson" "github.com/spf13/cobra" ) @@ -37,6 +38,10 @@ func format() error { return err } for _, optionsEntry := range optionsList { + optionsEntry.options, err = badjson.Omitempty(optionsEntry.options) + if err != nil { + return err + } buffer := new(bytes.Buffer) encoder := json.NewEncoder(buffer) encoder.SetIndent("", " ") diff --git a/cmd/sing-box/cmd_geoip_export.go b/cmd/sing-box/cmd_geoip_export.go index d170d10b..5787d2e5 100644 --- a/cmd/sing-box/cmd_geoip_export.go +++ b/cmd/sing-box/cmd_geoip_export.go @@ -6,11 +6,11 @@ import ( "os" "strings" - "github.com/sagernet/sing-box/common/json" C "github.com/sagernet/sing-box/constant" "github.com/sagernet/sing-box/log" "github.com/sagernet/sing-box/option" E "github.com/sagernet/sing/common/exceptions" + "github.com/sagernet/sing/common/json" "github.com/oschwald/maxminddb-golang" "github.com/spf13/cobra" diff --git a/cmd/sing-box/cmd_merge.go b/cmd/sing-box/cmd_merge.go index 4fb07b86..b5b08387 100644 --- a/cmd/sing-box/cmd_merge.go +++ b/cmd/sing-box/cmd_merge.go @@ -6,12 +6,12 @@ import ( "path/filepath" "strings" - "github.com/sagernet/sing-box/common/json" C "github.com/sagernet/sing-box/constant" "github.com/sagernet/sing-box/log" "github.com/sagernet/sing-box/option" "github.com/sagernet/sing/common" E "github.com/sagernet/sing/common/exceptions" + "github.com/sagernet/sing/common/json" "github.com/sagernet/sing/common/rw" "github.com/spf13/cobra" diff --git a/cmd/sing-box/cmd_rule_set_compile.go b/cmd/sing-box/cmd_rule_set_compile.go index de318095..e34f5d2b 100644 --- a/cmd/sing-box/cmd_rule_set_compile.go +++ b/cmd/sing-box/cmd_rule_set_compile.go @@ -5,10 +5,10 @@ import ( "os" "strings" - "github.com/sagernet/sing-box/common/json" "github.com/sagernet/sing-box/common/srs" "github.com/sagernet/sing-box/log" "github.com/sagernet/sing-box/option" + "github.com/sagernet/sing/common/json" "github.com/spf13/cobra" ) diff --git a/cmd/sing-box/cmd_rule_set_format.go b/cmd/sing-box/cmd_rule_set_format.go index dc3ee6aa..a3f98bd2 100644 --- a/cmd/sing-box/cmd_rule_set_format.go +++ b/cmd/sing-box/cmd_rule_set_format.go @@ -6,10 +6,10 @@ import ( "os" "path/filepath" - "github.com/sagernet/sing-box/common/json" "github.com/sagernet/sing-box/log" "github.com/sagernet/sing-box/option" E "github.com/sagernet/sing/common/exceptions" + "github.com/sagernet/sing/common/json" "github.com/spf13/cobra" ) diff --git a/cmd/sing-box/cmd_run.go b/cmd/sing-box/cmd_run.go index 46f3495f..9c54d61e 100644 --- a/cmd/sing-box/cmd_run.go +++ b/cmd/sing-box/cmd_run.go @@ -13,10 +13,10 @@ import ( "time" "github.com/sagernet/sing-box" - "github.com/sagernet/sing-box/common/badjsonmerge" "github.com/sagernet/sing-box/log" "github.com/sagernet/sing-box/option" E "github.com/sagernet/sing/common/exceptions" + "github.com/sagernet/sing/common/json/badjson" "github.com/spf13/cobra" ) @@ -108,7 +108,7 @@ func readConfigAndMerge() (option.Options, error) { } var mergedOptions option.Options for _, options := range optionsList { - mergedOptions, err = badjsonmerge.MergeOptions(options.options, mergedOptions) + mergedOptions, err = badjson.Merge(options.options, mergedOptions) if err != nil { return option.Options{}, E.Cause(err, "merge config at ", options.path) } diff --git a/common/badjson/array.go b/common/badjson/array.go deleted file mode 100644 index 2a731687..00000000 --- a/common/badjson/array.go +++ /dev/null @@ -1,46 +0,0 @@ -package badjson - -import ( - "bytes" - - "github.com/sagernet/sing-box/common/json" - E "github.com/sagernet/sing/common/exceptions" -) - -type JSONArray []any - -func (a JSONArray) MarshalJSON() ([]byte, error) { - return json.Marshal([]any(a)) -} - -func (a *JSONArray) UnmarshalJSON(content []byte) error { - decoder := json.NewDecoder(bytes.NewReader(content)) - arrayStart, err := decoder.Token() - if err != nil { - return err - } else if arrayStart != json.Delim('[') { - return E.New("excepted array start, but got ", arrayStart) - } - err = a.decodeJSON(decoder) - if err != nil { - return err - } - arrayEnd, err := decoder.Token() - if err != nil { - return err - } else if arrayEnd != json.Delim(']') { - return E.New("excepted array end, but got ", arrayEnd) - } - return nil -} - -func (a *JSONArray) decodeJSON(decoder *json.Decoder) error { - for decoder.More() { - item, err := decodeJSON(decoder) - if err != nil { - return err - } - *a = append(*a, item) - } - return nil -} diff --git a/common/badjson/json.go b/common/badjson/json.go deleted file mode 100644 index e2185b86..00000000 --- a/common/badjson/json.go +++ /dev/null @@ -1,54 +0,0 @@ -package badjson - -import ( - "bytes" - - "github.com/sagernet/sing-box/common/json" - E "github.com/sagernet/sing/common/exceptions" -) - -func Decode(content []byte) (any, error) { - decoder := json.NewDecoder(bytes.NewReader(content)) - return decodeJSON(decoder) -} - -func decodeJSON(decoder *json.Decoder) (any, error) { - rawToken, err := decoder.Token() - if err != nil { - return nil, err - } - switch token := rawToken.(type) { - case json.Delim: - switch token { - case '{': - var object JSONObject - err = object.decodeJSON(decoder) - if err != nil { - return nil, err - } - rawToken, err = decoder.Token() - if err != nil { - return nil, err - } else if rawToken != json.Delim('}') { - return nil, E.New("excepted object end, but got ", rawToken) - } - return &object, nil - case '[': - var array JSONArray - err = array.decodeJSON(decoder) - if err != nil { - return nil, err - } - rawToken, err = decoder.Token() - if err != nil { - return nil, err - } else if rawToken != json.Delim(']') { - return nil, E.New("excepted array end, but got ", rawToken) - } - return array, nil - default: - return nil, E.New("excepted object or array end: ", token) - } - } - return rawToken, nil -} diff --git a/common/badjson/object.go b/common/badjson/object.go deleted file mode 100644 index d9c2a36e..00000000 --- a/common/badjson/object.go +++ /dev/null @@ -1,79 +0,0 @@ -package badjson - -import ( - "bytes" - "strings" - - "github.com/sagernet/sing-box/common/json" - E "github.com/sagernet/sing/common/exceptions" - "github.com/sagernet/sing/common/x/linkedhashmap" -) - -type JSONObject struct { - linkedhashmap.Map[string, any] -} - -func (m JSONObject) MarshalJSON() ([]byte, error) { - buffer := new(bytes.Buffer) - buffer.WriteString("{") - items := m.Entries() - iLen := len(items) - for i, entry := range items { - keyContent, err := json.Marshal(entry.Key) - if err != nil { - return nil, err - } - buffer.WriteString(strings.TrimSpace(string(keyContent))) - buffer.WriteString(": ") - valueContent, err := json.Marshal(entry.Value) - if err != nil { - return nil, err - } - buffer.WriteString(strings.TrimSpace(string(valueContent))) - if i < iLen-1 { - buffer.WriteString(", ") - } - } - buffer.WriteString("}") - return buffer.Bytes(), nil -} - -func (m *JSONObject) UnmarshalJSON(content []byte) error { - decoder := json.NewDecoder(bytes.NewReader(content)) - m.Clear() - objectStart, err := decoder.Token() - if err != nil { - return err - } else if objectStart != json.Delim('{') { - return E.New("expected json object start, but starts with ", objectStart) - } - err = m.decodeJSON(decoder) - if err != nil { - return E.Cause(err, "decode json object content") - } - objectEnd, err := decoder.Token() - if err != nil { - return err - } else if objectEnd != json.Delim('}') { - return E.New("expected json object end, but ends with ", objectEnd) - } - return nil -} - -func (m *JSONObject) decodeJSON(decoder *json.Decoder) error { - for decoder.More() { - var entryKey string - keyToken, err := decoder.Token() - if err != nil { - return err - } - entryKey = keyToken.(string) - var entryValue any - entryValue, err = decodeJSON(decoder) - if err != nil { - return E.Cause(err, "decode value for ", entryKey) - } - m.Put(entryKey, entryValue) - } - return nil -} diff --git a/common/badjsonmerge/merge.go b/common/badjsonmerge/merge.go deleted file mode 100644 index 39635e66..00000000 --- a/common/badjsonmerge/merge.go +++ /dev/null @@ -1,80 +0,0 @@ -package badjsonmerge - -import ( - "encoding/json" - "reflect" - - "github.com/sagernet/sing-box/common/badjson" - "github.com/sagernet/sing-box/option" - E "github.com/sagernet/sing/common/exceptions" -) - -func MergeOptions(source option.Options, destination option.Options) (option.Options, error) { - rawSource, err := json.Marshal(source) - if err != nil { - return option.Options{}, E.Cause(err, "marshal source") - } - rawDestination, err := json.Marshal(destination) - if err != nil { - return option.Options{}, E.Cause(err, "marshal destination") - } - rawMerged, err := MergeJSON(rawSource, rawDestination) - if err != nil { - return option.Options{}, E.Cause(err, "merge options") - } - var merged option.Options - err = json.Unmarshal(rawMerged, &merged) - if err != nil { - return option.Options{}, E.Cause(err, "unmarshal merged options") - } - return merged, nil -} - -func MergeJSON(rawSource json.RawMessage, rawDestination json.RawMessage) (json.RawMessage, error) { - source, err := badjson.Decode(rawSource) - if err != nil { - return nil, E.Cause(err, "decode source") - } - destination, err := badjson.Decode(rawDestination) - if err != nil { - return nil, E.Cause(err, "decode destination") - } - merged, err := mergeJSON(source, destination) - if err != nil { - return nil, err - } - return json.Marshal(merged) -} - -func mergeJSON(anySource any, anyDestination any) (any, error) { - switch destination := anyDestination.(type) { - case badjson.JSONArray: - switch source := anySource.(type) { - case badjson.JSONArray: - destination = append(destination, source...) - default: - destination = append(destination, source) - } - return destination, nil - case *badjson.JSONObject: - switch source := anySource.(type) { - case *badjson.JSONObject: - for _, entry := range source.Entries() { - oldValue, loaded := destination.Get(entry.Key) - if loaded { - var err error - entry.Value, err = mergeJSON(entry.Value, oldValue) - if err != nil { - return nil, E.Cause(err, "merge object item ", entry.Key) - } - } - destination.Put(entry.Key, entry.Value) - } - default: - return nil, E.New("cannot merge json object into ", reflect.TypeOf(destination)) - } - return destination, nil - default: - return destination, nil - } -} diff --git a/common/badjsonmerge/merge_test.go b/common/badjsonmerge/merge_test.go deleted file mode 100644 index be4481b5..00000000 --- a/common/badjsonmerge/merge_test.go +++ /dev/null @@ -1,59 +0,0 @@ -package badjsonmerge - -import ( - "testing" - - C "github.com/sagernet/sing-box/constant" - "github.com/sagernet/sing-box/option" - N "github.com/sagernet/sing/common/network" - - "github.com/stretchr/testify/require" -) - -func TestMergeJSON(t *testing.T) { - t.Parallel() - options := option.Options{ - Log: &option.LogOptions{ - Level: "info", - }, - Route: &option.RouteOptions{ - Rules: []option.Rule{ - { - Type: C.RuleTypeDefault, - DefaultOptions: option.DefaultRule{ - Network: []string{N.NetworkTCP}, - Outbound: "direct", - }, - }, - }, - }, - } - anotherOptions := option.Options{ - Outbounds: []option.Outbound{ - { - Type: C.TypeDirect, - Tag: "direct", - }, - }, - } - thirdOptions := option.Options{ - Route: &option.RouteOptions{ - Rules: []option.Rule{ - { - Type: C.RuleTypeDefault, - DefaultOptions: option.DefaultRule{ - Network: []string{N.NetworkUDP}, - Outbound: "direct", - }, - }, - }, - }, - } - mergeOptions, err := MergeOptions(options, anotherOptions) - require.NoError(t, err) - mergeOptions, err = MergeOptions(thirdOptions, mergeOptions) - require.NoError(t, err) - require.Equal(t, "info", mergeOptions.Log.Level) - require.Equal(t, 2, len(mergeOptions.Route.Rules)) - require.Equal(t, C.TypeDirect, mergeOptions.Outbounds[0].Type) -} diff --git a/common/badversion/version_json.go b/common/badversion/version_json.go index 0647b2bf..7ec19663 100644 --- a/common/badversion/version_json.go +++ b/common/badversion/version_json.go @@ -1,6 +1,6 @@ package badversion -import "github.com/sagernet/sing-box/common/json" +import "github.com/sagernet/sing/common/json" func (v Version) MarshalJSON() ([]byte, error) { return json.Marshal(v.String()) diff --git a/common/json/comment.go b/common/json/comment.go deleted file mode 100644 index 6f3be262..00000000 --- a/common/json/comment.go +++ /dev/null @@ -1,128 +0,0 @@ -package json - -import ( - "bufio" - "io" -) - -// kanged from v2ray - -type commentFilterState = byte - -const ( - commentFilterStateContent commentFilterState = iota - commentFilterStateEscape - commentFilterStateDoubleQuote - commentFilterStateDoubleQuoteEscape - commentFilterStateSingleQuote - commentFilterStateSingleQuoteEscape - commentFilterStateComment - commentFilterStateSlash - commentFilterStateMultilineComment - commentFilterStateMultilineCommentStar -) - -type CommentFilter struct { - br *bufio.Reader - state commentFilterState -} - -func NewCommentFilter(reader io.Reader) io.Reader { - return &CommentFilter{br: bufio.NewReader(reader)} -} - -func (v *CommentFilter) Read(b []byte) (int, error) { - p := b[:0] - for len(p) < len(b)-2 { - x, err := v.br.ReadByte() - if err != nil { - if len(p) == 0 { - return 0, err - } - return len(p), nil - } - switch v.state { - case commentFilterStateContent: - switch x { - case '"': - v.state = commentFilterStateDoubleQuote - p = append(p, x) - case '\'': - v.state = commentFilterStateSingleQuote - p = append(p, x) - case '\\': - v.state = commentFilterStateEscape - case '#': - v.state = commentFilterStateComment - case '/': - v.state = commentFilterStateSlash - default: - p = append(p, x) - } - case commentFilterStateEscape: - p = append(p, '\\', x) - v.state = commentFilterStateContent - case commentFilterStateDoubleQuote: - switch x { - case '"': - v.state = commentFilterStateContent - p = append(p, x) - case '\\': - v.state = commentFilterStateDoubleQuoteEscape - default: - p = append(p, x) - } - case commentFilterStateDoubleQuoteEscape: - p = append(p, '\\', x) - v.state = commentFilterStateDoubleQuote - case commentFilterStateSingleQuote: - switch x { - case '\'': - v.state = commentFilterStateContent - p = append(p, x) - case '\\': - v.state = commentFilterStateSingleQuoteEscape - default: - p = append(p, x) - } - case commentFilterStateSingleQuoteEscape: - p = append(p, '\\', x) - v.state = commentFilterStateSingleQuote - case commentFilterStateComment: - if x == '\n' { - v.state = commentFilterStateContent - p = append(p, '\n') - } - case commentFilterStateSlash: - switch x { - case '/': - v.state = commentFilterStateComment - case '*': - v.state = commentFilterStateMultilineComment - default: - p = append(p, '/', x) - } - case commentFilterStateMultilineComment: - switch x { - case '*': - v.state = commentFilterStateMultilineCommentStar - case '\n': - p = append(p, '\n') - } - case commentFilterStateMultilineCommentStar: - switch x { - case '/': - v.state = commentFilterStateContent - case '*': - // Stay - case '\n': - p = append(p, '\n') - default: - v.state = commentFilterStateMultilineComment - } - default: - panic("Unknown state.") - } - } - return len(p), nil -} diff --git a/common/json/std.go b/common/json/std.go deleted file mode 100644 index edc3502b..00000000 --- a/common/json/std.go +++ /dev/null @@ -1,18 +0,0 @@ -package json - -import "encoding/json" - -var ( - Marshal = json.Marshal - Unmarshal = json.Unmarshal - NewEncoder = json.NewEncoder - NewDecoder = json.NewDecoder -) - -type ( - Encoder = json.Encoder - Decoder = json.Decoder - Token = json.Token - Delim = json.Delim - SyntaxError = json.SyntaxError -) diff --git a/debug_http.go b/debug_http.go index 7c675eba..09f015e7 100644 --- a/debug_http.go +++ b/debug_http.go @@ -6,12 +6,12 @@ import ( "runtime" "runtime/debug" - "github.com/sagernet/sing-box/common/badjson" "github.com/sagernet/sing-box/common/humanize" - "github.com/sagernet/sing-box/common/json" "github.com/sagernet/sing-box/log" "github.com/sagernet/sing-box/option" E "github.com/sagernet/sing/common/exceptions" + "github.com/sagernet/sing/common/json" + "github.com/sagernet/sing/common/json/badjson" "github.com/go-chi/chi/v5" ) diff --git a/experimental/clashapi/api_meta.go b/experimental/clashapi/api_meta.go index 876f9869..29add8ae 100644 --- a/experimental/clashapi/api_meta.go +++ b/experimental/clashapi/api_meta.go @@ -6,8 +6,8 @@ import ( "net/http" "time" - "github.com/sagernet/sing-box/common/json" "github.com/sagernet/sing-box/experimental/clashapi/trafficontrol" + "github.com/sagernet/sing/common/json" "github.com/sagernet/ws" "github.com/sagernet/ws/wsutil" diff --git a/experimental/clashapi/api_meta_group.go b/experimental/clashapi/api_meta_group.go index 763d3801..396dee7f 100644 --- a/experimental/clashapi/api_meta_group.go +++ b/experimental/clashapi/api_meta_group.go @@ -9,11 +9,11 @@ import ( "time" "github.com/sagernet/sing-box/adapter" - "github.com/sagernet/sing-box/common/badjson" "github.com/sagernet/sing-box/common/urltest" "github.com/sagernet/sing-box/outbound" "github.com/sagernet/sing/common" "github.com/sagernet/sing/common/batch" + "github.com/sagernet/sing/common/json/badjson" "github.com/go-chi/chi/v5" "github.com/go-chi/render" diff --git a/experimental/clashapi/connections.go b/experimental/clashapi/connections.go index 042bdd36..c9471207 100644 --- a/experimental/clashapi/connections.go +++ b/experimental/clashapi/connections.go @@ -7,8 +7,8 @@ import ( "time" "github.com/sagernet/sing-box/adapter" - "github.com/sagernet/sing-box/common/json" "github.com/sagernet/sing-box/experimental/clashapi/trafficontrol" + "github.com/sagernet/sing/common/json" "github.com/sagernet/ws" "github.com/sagernet/ws/wsutil" diff --git a/experimental/clashapi/proxies.go b/experimental/clashapi/proxies.go index cf96931a..7a807c1f 100644 --- a/experimental/clashapi/proxies.go +++ b/experimental/clashapi/proxies.go @@ -9,12 +9,12 @@ import ( "time" "github.com/sagernet/sing-box/adapter" - "github.com/sagernet/sing-box/common/badjson" "github.com/sagernet/sing-box/common/urltest" C "github.com/sagernet/sing-box/constant" "github.com/sagernet/sing-box/outbound" "github.com/sagernet/sing/common" F "github.com/sagernet/sing/common/format" + "github.com/sagernet/sing/common/json/badjson" N "github.com/sagernet/sing/common/network" "github.com/go-chi/chi/v5" diff --git a/experimental/clashapi/server.go b/experimental/clashapi/server.go index c40ff938..1eec8448 100644 --- a/experimental/clashapi/server.go +++ b/experimental/clashapi/server.go @@ -11,7 +11,6 @@ import ( "time" "github.com/sagernet/sing-box/adapter" - "github.com/sagernet/sing-box/common/json" "github.com/sagernet/sing-box/common/urltest" C "github.com/sagernet/sing-box/constant" "github.com/sagernet/sing-box/experimental" @@ -21,6 +20,7 @@ import ( "github.com/sagernet/sing/common" E "github.com/sagernet/sing/common/exceptions" F "github.com/sagernet/sing/common/format" + "github.com/sagernet/sing/common/json" N "github.com/sagernet/sing/common/network" "github.com/sagernet/sing/service" "github.com/sagernet/sing/service/filemanager" diff --git a/option/config.go b/option/config.go index ec471112..3cec5520 100644 --- a/option/config.go +++ b/option/config.go @@ -4,8 +4,8 @@ import ( "bytes" "strings" - "github.com/sagernet/sing-box/common/json" E "github.com/sagernet/sing/common/exceptions" + "github.com/sagernet/sing/common/json" ) type _Options struct { diff --git a/option/inbound.go b/option/inbound.go index c61428ad..a2b23461 100644 --- a/option/inbound.go +++ b/option/inbound.go @@ -1,9 +1,9 @@ package option import ( - "github.com/sagernet/sing-box/common/json" C "github.com/sagernet/sing-box/constant" E "github.com/sagernet/sing/common/exceptions" + "github.com/sagernet/sing/common/json" ) type _Inbound struct { @@ -114,7 +114,7 @@ func (h *Inbound) UnmarshalJSON(bytes []byte) error { } err = UnmarshallExcluded(bytes, (*_Inbound)(h), v) if err != nil { - return E.Cause(err, "inbound options") + return err } return nil } diff --git a/option/json.go b/option/json.go index d010da32..07580e9f 100644 --- a/option/json.go +++ b/option/json.go @@ -3,10 +3,10 @@ package option import ( "bytes" - "github.com/sagernet/sing-box/common/badjson" - "github.com/sagernet/sing-box/common/json" "github.com/sagernet/sing/common" E "github.com/sagernet/sing/common/exceptions" + "github.com/sagernet/sing/common/json" + "github.com/sagernet/sing/common/json/badjson" ) func ToMap(v any) (*badjson.JSONObject, error) { diff --git a/option/outbound.go b/option/outbound.go index 2985319e..f6593228 100644 --- a/option/outbound.go +++ b/option/outbound.go @@ -1,9 +1,9 @@ package option import ( - "github.com/sagernet/sing-box/common/json" C "github.com/sagernet/sing-box/constant" E "github.com/sagernet/sing/common/exceptions" + "github.com/sagernet/sing/common/json" M "github.com/sagernet/sing/common/metadata" ) @@ -124,7 +124,7 @@ func (h *Outbound) UnmarshalJSON(bytes []byte) error { } err = UnmarshallExcluded(bytes, (*_Outbound)(h), v) if err != nil { - return E.Cause(err, "outbound options") + return err } return nil } diff --git a/option/platform.go b/option/platform.go index fd3d73f0..a43cbf23 100644 --- a/option/platform.go +++ b/option/platform.go @@ -1,8 +1,8 @@ package option import ( - "github.com/sagernet/sing-box/common/json" E "github.com/sagernet/sing/common/exceptions" + "github.com/sagernet/sing/common/json" ) type OnDemandOptions struct { diff --git a/option/rule.go b/option/rule.go index 1201d123..0ea133c7 100644 --- a/option/rule.go +++ b/option/rule.go @@ -3,10 +3,10 @@ package option import ( "reflect" - "github.com/sagernet/sing-box/common/json" C "github.com/sagernet/sing-box/constant" "github.com/sagernet/sing/common" E "github.com/sagernet/sing/common/exceptions" + "github.com/sagernet/sing/common/json" ) type _Rule struct { @@ -48,7 +48,7 @@ func (r *Rule) UnmarshalJSON(bytes []byte) error { } err = UnmarshallExcluded(bytes, (*_Rule)(r), v) if err != nil { - return E.Cause(err, "route rule") + return err } return nil } diff --git a/option/rule_dns.go b/option/rule_dns.go index 50d9e612..443f9314 100644 --- a/option/rule_dns.go +++ b/option/rule_dns.go @@ -3,10 +3,10 @@ package option import ( "reflect" - "github.com/sagernet/sing-box/common/json" C "github.com/sagernet/sing-box/constant" "github.com/sagernet/sing/common" E "github.com/sagernet/sing/common/exceptions" + "github.com/sagernet/sing/common/json" ) type _DNSRule struct { @@ -48,7 +48,7 @@ func (r *DNSRule) UnmarshalJSON(bytes []byte) error { } err = UnmarshallExcluded(bytes, (*_DNSRule)(r), v) if err != nil { - return E.Cause(err, "dns route rule") + return err } return nil } diff --git a/option/rule_set.go b/option/rule_set.go index 1b758142..8e367e69 100644 --- a/option/rule_set.go +++ b/option/rule_set.go @@ -3,12 +3,12 @@ package option import ( "reflect" - "github.com/sagernet/sing-box/common/json" C "github.com/sagernet/sing-box/constant" "github.com/sagernet/sing/common" "github.com/sagernet/sing/common/domain" E "github.com/sagernet/sing/common/exceptions" F "github.com/sagernet/sing/common/format" + "github.com/sagernet/sing/common/json" "go4.org/netipx" ) @@ -64,7 +64,7 @@ func (r *RuleSet) UnmarshalJSON(bytes []byte) error { } err = UnmarshallExcluded(bytes, (*_RuleSet)(r), v) if err != nil { - return E.Cause(err, "rule set") + return err } return nil } @@ -118,7 +118,7 @@ func (r *HeadlessRule) UnmarshalJSON(bytes []byte) error { } err = UnmarshallExcluded(bytes, (*_HeadlessRule)(r), v) if err != nil { - return E.Cause(err, "route rule-set rule") + return err } return nil } @@ -209,7 +209,7 @@ func (r *PlainRuleSetCompat) UnmarshalJSON(bytes []byte) error { } err = UnmarshallExcluded(bytes, (*_PlainRuleSetCompat)(r), v) if err != nil { - return E.Cause(err, "rule set") + return err } return nil } diff --git a/option/tls_acme.go b/option/tls_acme.go index 1068237e..aa3f2377 100644 --- a/option/tls_acme.go +++ b/option/tls_acme.go @@ -1,9 +1,9 @@ package option import ( - "github.com/sagernet/sing-box/common/json" C "github.com/sagernet/sing-box/constant" E "github.com/sagernet/sing/common/exceptions" + "github.com/sagernet/sing/common/json" ) type InboundACMEOptions struct { @@ -62,7 +62,7 @@ func (o *ACMEDNS01ChallengeOptions) UnmarshalJSON(bytes []byte) error { } err = UnmarshallExcluded(bytes, (*_ACMEDNS01ChallengeOptions)(o), v) if err != nil { - return E.Cause(err, "DNS01 challenge options") + return err } return nil } diff --git a/option/types.go b/option/types.go index 2f029098..6f0129af 100644 --- a/option/types.go +++ b/option/types.go @@ -6,10 +6,10 @@ import ( "strings" "time" - "github.com/sagernet/sing-box/common/json" "github.com/sagernet/sing-dns" E "github.com/sagernet/sing/common/exceptions" F "github.com/sagernet/sing/common/format" + "github.com/sagernet/sing/common/json" N "github.com/sagernet/sing/common/network" mDNS "github.com/miekg/dns" diff --git a/option/udp_over_tcp.go b/option/udp_over_tcp.go index 79529624..e8a7a972 100644 --- a/option/udp_over_tcp.go +++ b/option/udp_over_tcp.go @@ -1,7 +1,7 @@ package option import ( - "github.com/sagernet/sing-box/common/json" + "github.com/sagernet/sing/common/json" "github.com/sagernet/sing/common/uot" ) diff --git a/option/v2ray_transport.go b/option/v2ray_transport.go index 63af28a3..56fb71d6 100644 --- a/option/v2ray_transport.go +++ b/option/v2ray_transport.go @@ -1,9 +1,9 @@ package option import ( - "github.com/sagernet/sing-box/common/json" C "github.com/sagernet/sing-box/constant" E "github.com/sagernet/sing/common/exceptions" + "github.com/sagernet/sing/common/json" ) type _V2RayTransportOptions struct { @@ -60,7 +60,7 @@ func (o *V2RayTransportOptions) UnmarshalJSON(bytes []byte) error { } err = UnmarshallExcluded(bytes, (*_V2RayTransportOptions)(o), v) if err != nil { - return E.Cause(err, "vmess transport options") + return err } return nil } diff --git a/route/rule_set_local.go b/route/rule_set_local.go index d89d78c3..b6424ab3 100644 --- a/route/rule_set_local.go +++ b/route/rule_set_local.go @@ -5,11 +5,11 @@ import ( "os" "github.com/sagernet/sing-box/adapter" - "github.com/sagernet/sing-box/common/json" "github.com/sagernet/sing-box/common/srs" C "github.com/sagernet/sing-box/constant" "github.com/sagernet/sing-box/option" E "github.com/sagernet/sing/common/exceptions" + "github.com/sagernet/sing/common/json" ) var _ adapter.RuleSet = (*LocalRuleSet)(nil) diff --git a/route/rule_set_remote.go b/route/rule_set_remote.go index 957e712d..ac939a45 100644 --- a/route/rule_set_remote.go +++ b/route/rule_set_remote.go @@ -10,11 +10,11 @@ import ( "time" "github.com/sagernet/sing-box/adapter" - "github.com/sagernet/sing-box/common/json" "github.com/sagernet/sing-box/common/srs" C "github.com/sagernet/sing-box/constant" "github.com/sagernet/sing-box/option" E "github.com/sagernet/sing/common/exceptions" + "github.com/sagernet/sing/common/json" "github.com/sagernet/sing/common/logger" M "github.com/sagernet/sing/common/metadata" N "github.com/sagernet/sing/common/network"