brain/config.go

47 lines
606 B
Go
Raw Permalink Normal View History

2023-07-03 02:42:43 +00:00
package brain
2023-07-04 02:08:43 +00:00
import (
"io"
"os"
"sync"
"gopkg.in/yaml.v3"
)
2023-07-03 02:42:43 +00:00
// Config 配置
type Config struct {
2023-07-04 02:08:43 +00:00
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
2023-07-03 02:42:43 +00:00
}