summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorLoyalsoldier <[email protected]>2024-10-24 07:08:01 +0800
committerLoyalsoldier <[email protected]>2024-10-24 07:16:35 +0800
commit87404b7cbcdaa441ed812434852c8aef5c7a5405 (patch)
treecba8087d721c857875fc6fd6e34af3eae3727583 /lib
parente6ee2bb6c610a8f7f9ca86da9ebe27e59c2daef3 (diff)
Feat: support JSON configuration with comments and trailing commas
Diffstat (limited to 'lib')
-rw-r--r--lib/instance.go8
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
}