Do not pass the config object to newCluster
Decouple the config structure from the cluster management and stop passing the config object around.
This commit is contained in:
parent
97525f4b10
commit
366f906d5d
16
cluster.go
16
cluster.go
|
@ -34,11 +34,9 @@ type cluster struct {
|
||||||
|
|
||||||
const statePath = "/var/lib/wesher/state.json"
|
const statePath = "/var/lib/wesher/state.json"
|
||||||
|
|
||||||
func newCluster(config *config, getMeta func(int) []byte) (*cluster, error) {
|
func newCluster(init bool, clusterKey []byte, bindAddr string, bindIface string, bindPort int, useIPAsName bool, getMeta func(int) []byte) (*cluster, error) {
|
||||||
clusterKey := config.ClusterKey
|
|
||||||
|
|
||||||
state := &ClusterState{}
|
state := &ClusterState{}
|
||||||
if !config.Init {
|
if !init {
|
||||||
loadState(state)
|
loadState(state)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,7 +45,7 @@ func newCluster(config *config, getMeta func(int) []byte) (*cluster, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
bindAddr, err := computeBindAddr(config.BindAddr, config.BindIface)
|
bindAddr, err = computeBindAddr(bindAddr, bindIface)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
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.LogOutput = logrus.StandardLogger().WriterLevel(logrus.DebugLevel)
|
||||||
mlConfig.SecretKey = clusterKey
|
mlConfig.SecretKey = clusterKey
|
||||||
mlConfig.BindAddr = bindAddr
|
mlConfig.BindAddr = bindAddr
|
||||||
mlConfig.BindPort = config.ClusterPort
|
mlConfig.BindPort = bindPort
|
||||||
mlConfig.AdvertisePort = config.ClusterPort
|
mlConfig.AdvertisePort = bindPort
|
||||||
if config.UseIPAsName && config.BindAddr != "0.0.0.0" {
|
if useIPAsName && bindAddr != "0.0.0.0" {
|
||||||
mlConfig.Name = config.BindAddr
|
mlConfig.Name = bindAddr
|
||||||
}
|
}
|
||||||
|
|
||||||
ml, err := memberlist.Create(mlConfig)
|
ml, err := memberlist.Create(mlConfig)
|
||||||
|
|
2
main.go
2
main.go
|
@ -42,7 +42,7 @@ func main() {
|
||||||
}, limit)
|
}, 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 {
|
if err != nil {
|
||||||
logrus.WithError(err).Fatal("could not create cluster")
|
logrus.WithError(err).Fatal("could not create cluster")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue