mirror of
https://github.com/wyx2685/V2bX.git
synced 2026-02-04 04:30:08 +00:00
尝试优化代码
This commit is contained in:
18
conf/conf.go
18
conf/conf.go
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user