V2bX/conf/conf.go
2023-08-20 15:13:52 +08:00

33 lines
527 B
Go

package conf
import (
"fmt"
"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(f).Decode(p)
}