diff --git a/cluster.go b/cluster.go index 0e1c428..d8bfd70 100644 --- a/cluster.go +++ b/cluster.go @@ -34,11 +34,9 @@ type cluster struct { const statePath = "/var/lib/wesher/state.json" -func newCluster(config *config, getMeta func(int) []byte) (*cluster, error) { - clusterKey := config.ClusterKey - +func newCluster(init bool, clusterKey []byte, bindAddr string, bindIface string, bindPort int, useIPAsName bool, getMeta func(int) []byte) (*cluster, error) { state := &ClusterState{} - if !config.Init { + if !init { loadState(state) } @@ -47,7 +45,7 @@ func newCluster(config *config, getMeta func(int) []byte) (*cluster, error) { return nil, err } - bindAddr, err := computeBindAddr(config.BindAddr, config.BindIface) + bindAddr, err = computeBindAddr(bindAddr, bindIface) if err != nil { return nil, err } @@ -56,10 +54,10 @@ func newCluster(config *config, getMeta func(int) []byte) (*cluster, error) { mlConfig.LogOutput = logrus.StandardLogger().WriterLevel(logrus.DebugLevel) mlConfig.SecretKey = clusterKey mlConfig.BindAddr = bindAddr - mlConfig.BindPort = config.ClusterPort - mlConfig.AdvertisePort = config.ClusterPort - if config.UseIPAsName && config.BindAddr != "0.0.0.0" { - mlConfig.Name = config.BindAddr + mlConfig.BindPort = bindPort + mlConfig.AdvertisePort = bindPort + if useIPAsName && bindAddr != "0.0.0.0" { + mlConfig.Name = bindAddr } ml, err := memberlist.Create(mlConfig) diff --git a/main.go b/main.go index 572d407..53bc7aa 100644 --- a/main.go +++ b/main.go @@ -42,7 +42,7 @@ func main() { }, limit) } - cluster, err := newCluster(config, getMeta) + cluster, err := newCluster(config.Init, config.ClusterKey, config.BindAddr, config.BindIface, config.ClusterPort, config.UseIPAsName, getMeta) if err != nil { logrus.WithError(err).Fatal("could not create cluster") }