diff --git a/cmd/sing-box/cmd_run.go b/cmd/sing-box/cmd_run.go index d76d3b9c..ba729472 100644 --- a/cmd/sing-box/cmd_run.go +++ b/cmd/sing-box/cmd_run.go @@ -17,6 +17,7 @@ import ( "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/spf13/cobra" @@ -107,13 +108,18 @@ func readConfigAndMerge() (option.Options, error) { if len(optionsList) == 1 { return optionsList[0].options, nil } - var mergedOptions option.Options + var mergedMessage json.RawMessage for _, options := range optionsList { - mergedOptions, err = badjson.Merge(options.options, mergedOptions) + mergedMessage, err = badjson.MergeJSON(options.options.RawMessage, mergedMessage) if err != nil { return option.Options{}, E.Cause(err, "merge config at ", options.path) } } + var mergedOptions option.Options + err = mergedOptions.UnmarshalJSON(mergedMessage) + if err != nil { + return option.Options{}, E.Cause(err, "unmarshal merged config") + } return mergedOptions, nil } diff --git a/go.mod b/go.mod index 554a4ccf..b9a18564 100644 --- a/go.mod +++ b/go.mod @@ -26,7 +26,7 @@ require ( github.com/sagernet/gvisor v0.0.0-20231209105102-8d27a30e436e github.com/sagernet/quic-go v0.40.0 github.com/sagernet/reality v0.0.0-20230406110435-ee17307e7691 - github.com/sagernet/sing v0.2.19-0.20231209022445-766839c00099 + github.com/sagernet/sing v0.2.19-0.20231211084415-35e7014b0898 github.com/sagernet/sing-dns v0.1.11 github.com/sagernet/sing-mux v0.1.6-0.20231207143704-9f6c20fb5266 github.com/sagernet/sing-quic v0.1.6-0.20231207143711-eb3cbf9ed054 diff --git a/go.sum b/go.sum index 0896f697..03429bb8 100644 --- a/go.sum +++ b/go.sum @@ -109,8 +109,8 @@ github.com/sagernet/quic-go v0.40.0/go.mod h1:VqtdhlbkeeG5Okhb3eDMb/9o0EoglReHun github.com/sagernet/reality v0.0.0-20230406110435-ee17307e7691 h1:5Th31OC6yj8byLGkEnIYp6grlXfo1QYUfiYFGjewIdc= github.com/sagernet/reality v0.0.0-20230406110435-ee17307e7691/go.mod h1:B8lp4WkQ1PwNnrVMM6KyuFR20pU8jYBD+A4EhJovEXU= github.com/sagernet/sing v0.2.18/go.mod h1:OL6k2F0vHmEzXz2KW19qQzu172FDgSbUSODylighuVo= -github.com/sagernet/sing v0.2.19-0.20231209022445-766839c00099 h1:q/efB3NAhVolSoBe0oDc7eZ7/72+OZITWVwn0o92Hp0= -github.com/sagernet/sing v0.2.19-0.20231209022445-766839c00099/go.mod h1:Ce5LNojQOgOiWhiD8pPD6E9H7e2KgtOe3Zxx4Ou5u80= +github.com/sagernet/sing v0.2.19-0.20231211084415-35e7014b0898 h1:UsIwOvI9JAsUeRBFv6joJUW2CvH7yTzwr86OF2+hBCg= +github.com/sagernet/sing v0.2.19-0.20231211084415-35e7014b0898/go.mod h1:Ce5LNojQOgOiWhiD8pPD6E9H7e2KgtOe3Zxx4Ou5u80= github.com/sagernet/sing-dns v0.1.11 h1:PPrMCVVrAeR3f5X23I+cmvacXJ+kzuyAsBiWyUKhGSE= github.com/sagernet/sing-dns v0.1.11/go.mod h1:zJ/YjnYB61SYE+ubMcMqVdpaSvsyQ2iShQGO3vuLvvE= github.com/sagernet/sing-mux v0.1.6-0.20231207143704-9f6c20fb5266 h1:QqwwUyEfmOuoGVTZ2cYvUJEeSWlzunvQLRmv+9B41uk= diff --git a/option/config.go b/option/config.go index 3cec5520..724bfce6 100644 --- a/option/config.go +++ b/option/config.go @@ -9,6 +9,7 @@ import ( ) type _Options struct { + RawMessage json.RawMessage `json:"-"` Schema string `json:"$schema,omitempty"` Log *LogOptions `json:"log,omitempty"` DNS *DNSOptions `json:"dns,omitempty"` @@ -26,6 +27,7 @@ func (o *Options) UnmarshalJSON(content []byte) error { decoder.DisallowUnknownFields() err := decoder.Decode((*_Options)(o)) if err == nil { + o.RawMessage = content return nil } if syntaxError, isSyntaxError := err.(*json.SyntaxError); isSyntaxError {