Skip to content

Commit

Permalink
Migrate contentjson and badjson to library &
Browse files Browse the repository at this point in the history
Add omitempty in format
  • Loading branch information
nekohasekai committed Jan 3, 2024
1 parent e09a94b commit 38d28e0
Show file tree
Hide file tree
Showing 38 changed files with 48 additions and 508 deletions.
7 changes: 6 additions & 1 deletion cmd/sing-box/cmd_format.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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("", " ")
Expand Down
2 changes: 1 addition & 1 deletion cmd/sing-box/cmd_geoip_export.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion cmd/sing-box/cmd_geosite_export.go
Original file line number Diff line number Diff line change
@@ -1,14 1,14 @@
package main

import (
"encoding/json"
"io"
"os"

"github.com/sagernet/sing-box/common/geosite"
C "github.com/sagernet/sing-box/constant"
"github.com/sagernet/sing-box/log"
"github.com/sagernet/sing-box/option"
"github.com/sagernet/sing/common/json"

"github.com/spf13/cobra"
)
Expand Down
2 changes: 1 addition & 1 deletion cmd/sing-box/cmd_merge.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion cmd/sing-box/cmd_rule_set_compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down
2 changes: 1 addition & 1 deletion cmd/sing-box/cmd_rule_set_format.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down
4 changes: 2 additions & 2 deletions cmd/sing-box/cmd_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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)
}
Expand Down
46 changes: 0 additions & 46 deletions common/badjson/array.go

This file was deleted.

54 changes: 0 additions & 54 deletions common/badjson/json.go

This file was deleted.

79 changes: 0 additions & 79 deletions common/badjson/object.go

This file was deleted.

80 changes: 0 additions & 80 deletions common/badjsonmerge/merge.go

This file was deleted.

Loading

0 comments on commit 38d28e0

Please sign in to comment.