2022-07-28 23:00:05 +08:00
|
|
|
package conf
|
|
|
|
|
2022-09-13 11:08:20 +08:00
|
|
|
import (
|
|
|
|
"fmt"
|
2023-08-20 22:24:57 +08:00
|
|
|
"github.com/InazumaV/V2bX/common/json5"
|
2022-09-13 11:08:20 +08:00
|
|
|
"os"
|
2023-07-29 18:47:47 +08:00
|
|
|
|
2023-08-20 15:13:52 +08:00
|
|
|
"github.com/goccy/go-json"
|
2022-09-13 11:08:20 +08:00
|
|
|
)
|
|
|
|
|
2022-07-28 23:00:05 +08:00
|
|
|
type Conf struct {
|
2023-08-20 15:13:52 +08:00
|
|
|
LogConfig LogConfig `json:"Log"`
|
|
|
|
CoresConfig []CoreConfig `json:"Cores"`
|
|
|
|
NodeConfig []NodeConfig `json:"Nodes"`
|
2022-07-28 23:00:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func New() *Conf {
|
|
|
|
return &Conf{
|
2023-08-20 15:13:52 +08:00
|
|
|
LogConfig: LogConfig{
|
|
|
|
Level: "info",
|
|
|
|
Output: "",
|
2023-06-08 01:18:56 +08:00
|
|
|
},
|
2022-07-28 23:00:05 +08:00
|
|
|
}
|
|
|
|
}
|
2022-09-13 11:08:20 +08:00
|
|
|
|
|
|
|
func (p *Conf) LoadFromPath(filePath string) error {
|
|
|
|
f, err := os.Open(filePath)
|
|
|
|
if err != nil {
|
2022-10-10 11:31:15 +08:00
|
|
|
return fmt.Errorf("open config file error: %s", err)
|
2022-09-13 11:08:20 +08:00
|
|
|
}
|
2023-06-02 09:19:37 +08:00
|
|
|
defer f.Close()
|
2023-08-20 22:24:57 +08:00
|
|
|
return json.NewDecoder(json5.NewTrimNodeReader(f)).Decode(p)
|
2022-10-10 11:31:15 +08:00
|
|
|
}
|