diff options
| author | Loyalsoldier <[email protected]> | 2024-10-24 07:08:01 +0800 |
|---|---|---|
| committer | Loyalsoldier <[email protected]> | 2024-10-24 07:16:35 +0800 |
| commit | 87404b7cbcdaa441ed812434852c8aef5c7a5405 (patch) | |
| tree | cba8087d721c857875fc6fd6e34af3eae3727583 /lib | |
| parent | e6ee2bb6c610a8f7f9ca86da9ebe27e59c2daef3 (diff) | |
Feat: support JSON configuration with comments and trailing commas
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/instance.go | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/lib/instance.go b/lib/instance.go index 79949c0f..0a16442e 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 } |
