diff --git a/go.mod b/go.mod index a0dda17d9c4..c455e26d1cb 100644 --- a/go.mod +++ b/go.mod @@ -1,8 +1,8 @@ module github.com/Loyalsoldier/geoip -go 1.22 +go 1.23 -toolchain go1.22.6 +toolchain go1.23.2 require ( github.com/klauspost/compress v1.17.10 @@ -10,6 +10,7 @@ require ( github.com/oschwald/maxminddb-golang v1.13.1 github.com/sagernet/sing-box v1.9.7 github.com/spf13/cobra v1.8.1 + github.com/tailscale/hujson v0.0.0-20241010212012-29efb4a0184b github.com/tidwall/gjson v1.18.0 go4.org/netipx v0.0.0-20231129151722-fdeea329fbba google.golang.org/protobuf v1.35.1 diff --git a/go.sum b/go.sum index b72cc240064..75e7031b954 100644 --- a/go.sum +++ b/go.sum @@ -45,6 +45,8 @@ github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/tailscale/hujson v0.0.0-20241010212012-29efb4a0184b h1:MNaGusDfB1qxEsl6iVb33Gbe777IKzPP5PDta0xGC8M= +github.com/tailscale/hujson v0.0.0-20241010212012-29efb4a0184b/go.mod h1:EbW0wDK/qEUYI0A5bqq0C2kF8JTQwWONmGDBbzsxxHo= github.com/tidwall/gjson v1.18.0 h1:FIDeeyB800efLX89e5a8Y0BNH+LOngJyGrIWxG2FKQY= github.com/tidwall/gjson v1.18.0/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk= github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA= diff --git a/lib/instance.go b/lib/instance.go index 79949c0f7d9..0a16442e55c 100644 --- a/lib/instance.go +++ b/lib/instance.go @@ -5,6 +5,8 @@ import ( "errors" "os" "strings" + + "github.com/tailscale/hujson" ) type Instance struct { @@ -34,6 +36,9 @@ func (i *Instance) Init(configFile string) error { return err } + // Support JSON with comments and trailing commas + content, _ = hujson.Standardize(content) + if err := json.Unmarshal(content, &i.config); err != nil { return err } @@ -50,6 +55,9 @@ func (i *Instance) Init(configFile string) error { } func (i *Instance) InitFromBytes(content []byte) error { + // Support JSON with comments and trailing commas + content, _ = hujson.Standardize(content) + if err := json.Unmarshal(content, &i.config); err != nil { return err }