refactor conf

This commit is contained in:
Yuzuki616
2023-08-20 15:13:52 +08:00
parent 42407d5c62
commit 214324496d
19 changed files with 346 additions and 287 deletions

View File

@@ -2,25 +2,23 @@ package conf
import (
"fmt"
"io"
"os"
"gopkg.in/yaml.v3"
"github.com/goccy/go-json"
)
type Conf struct {
CoreConfig CoreConfig `yaml:"CoreConfig"`
NodesConfig []*NodeConfig `yaml:"Nodes"`
LogConfig LogConfig `json:"Log"`
CoresConfig []CoreConfig `json:"Cores"`
NodeConfig []NodeConfig `json:"Nodes"`
}
func New() *Conf {
return &Conf{
CoreConfig: CoreConfig{
Type: "xray",
XrayConfig: NewXrayConfig(),
SingConfig: NewSingConfig(),
LogConfig: LogConfig{
Level: "info",
Output: "",
},
NodesConfig: []*NodeConfig{},
}
}
@@ -30,13 +28,5 @@ func (p *Conf) LoadFromPath(filePath string) error {
return fmt.Errorf("open config file error: %s", err)
}
defer f.Close()
content, err := io.ReadAll(f)
if err != nil {
return fmt.Errorf("read file error: %s", err)
}
err = yaml.Unmarshal(content, p)
if err != nil {
return fmt.Errorf("decode config error: %s", err)
}
return nil
return json.NewDecoder(f).Decode(p)
}