V2bX/conf/conf.go
2023-08-20 22:24:57 +08:00

34 lines
593 B
Go

package conf
import (
"fmt"
"github.com/InazumaV/V2bX/common/json5"
"os"
"github.com/goccy/go-json"
)
type Conf struct {
LogConfig LogConfig `json:"Log"`
CoresConfig []CoreConfig `json:"Cores"`
NodeConfig []NodeConfig `json:"Nodes"`
}
func New() *Conf {
return &Conf{
LogConfig: LogConfig{
Level: "info",
Output: "",
},
}
}
func (p *Conf) LoadFromPath(filePath string) error {
f, err := os.Open(filePath)
if err != nil {
return fmt.Errorf("open config file error: %s", err)
}
defer f.Close()
return json.NewDecoder(json5.NewTrimNodeReader(f)).Decode(p)
}