support notes for config

This commit is contained in:
yuzuki999
2023-08-20 22:24:57 +08:00
parent 0fce6588da
commit c3bb809c71
5 changed files with 170 additions and 35 deletions

View File

@@ -2,6 +2,7 @@ package conf
import (
"fmt"
"github.com/InazumaV/V2bX/common/json5"
"os"
"github.com/goccy/go-json"
@@ -28,5 +29,5 @@ func (p *Conf) LoadFromPath(filePath string) error {
return fmt.Errorf("open config file error: %s", err)
}
defer f.Close()
return json.NewDecoder(f).Decode(p)
return json.NewDecoder(json5.NewTrimNodeReader(f)).Decode(p)
}

View File

@@ -6,7 +6,7 @@ import (
func TestConf_LoadFromPath(t *testing.T) {
c := New()
t.Log(c.LoadFromPath("./config.json"), c.NodeConfig)
t.Log(c.LoadFromPath("../example/config.json"), c.NodeConfig)
}
func TestConf_Watch(t *testing.T) {