From 87404b7cbcdaa441ed812434852c8aef5c7a5405 Mon Sep 17 00:00:00 2001 From: Loyalsoldier <10487845+Loyalsoldier@users.noreply.github.com> Date: Thu, 24 Oct 2024 07:08:01 +0800 Subject: Feat: support JSON configuration with comments and trailing commas --- lib/instance.go | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'lib/instance.go') 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 } -- cgit v1.3.1