尝试优化代码

This commit is contained in:
wyx2685
2024-01-25 23:06:37 +09:00
parent e292b3b0e7
commit 91e78fbc20
7 changed files with 66 additions and 24 deletions

View File

@@ -2,9 +2,11 @@ package conf
import (
"fmt"
"github.com/InazumaV/V2bX/common/json5"
"io"
"os"
"github.com/InazumaV/V2bX/common/json5"
"github.com/goccy/go-json"
)
@@ -29,5 +31,17 @@ func (p *Conf) LoadFromPath(filePath string) error {
return fmt.Errorf("open config file error: %s", err)
}
defer f.Close()
return json.NewDecoder(json5.NewTrimNodeReader(f)).Decode(p)
reader := json5.NewTrimNodeReader(f)
data, err := io.ReadAll(reader)
if err != nil {
return fmt.Errorf("read config file error: %s", err)
}
err = json.Unmarshal(data, p)
if err != nil {
return fmt.Errorf("unmarshal config error: %s", err)
}
return nil
}