48 lines
995 B
Go
48 lines
995 B
Go
package config
|
|
|
|
import (
|
|
"errors"
|
|
"gopkg.in/yaml.v2"
|
|
"os"
|
|
)
|
|
|
|
func ParseFile(file string) (cfg *Config, err error) {
|
|
if file == "" {
|
|
return nil, errors.New("missing config file")
|
|
}
|
|
f, err := os.Open(file)
|
|
if err != nil {
|
|
return
|
|
}
|
|
cfg = new(Config)
|
|
err = yaml.NewDecoder(f).Decode(cfg)
|
|
return
|
|
}
|
|
|
|
type Config struct {
|
|
RaftDir string `yaml:"raftDir"`
|
|
|
|
Leader bool `yaml:"leader"`
|
|
|
|
AddressRange []string `yaml:"addressRange"`
|
|
|
|
// LocalPeer is the configuration of this host
|
|
LocalPeer RaftPeer `yaml:"localPeer"`
|
|
|
|
// Peers are all of the peers within the RAFT cluster
|
|
RemotePeers []RaftPeer `yaml:"remotePeers"`
|
|
|
|
// Interface is the network interface to bind to (default: First Adapter)
|
|
Interface string `yaml:"interface,omitempty"`
|
|
}
|
|
|
|
// RaftPeer details the configuration of all cluster peers
|
|
type RaftPeer struct {
|
|
ID string `yaml:"id"`
|
|
|
|
// IP Address of a peer instance
|
|
Address string `yaml:"address"`
|
|
|
|
// Listening port of this peer instance
|
|
Port int `yaml:"port"`
|
|
}
|