initial commit
This commit is contained in:
commit
c0616030c6
14 changed files with 1468 additions and 0 deletions
48
pkg/config/config.go
Normal file
48
pkg/config/config.go
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
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 {
|
||||
DBFile string `yaml:"dbFile"`
|
||||
|
||||
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"`
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue