package brain import ( "io" "os" "sync" "gopkg.in/yaml.v3" ) // Config 配置 type Config struct { cnfLock sync.Mutex Cluster `yaml:"cluster"` Self `yaml:"self"` } type Cluster struct { Member []string `yaml:"member"` } type Self struct { Addr string `yaml:"addr"` Candidate struct { Weight int `yaml:"weight"` } `yaml:"candidate"` } func (cnf *Config) Load(pth string) error { f, err := os.Open(pth) if err != nil { return err } data, err := io.ReadAll(f) if err != nil { return err } err = yaml.Unmarshal(data, cnf) if err != nil { return err } return nil }