diff --git a/cluster/cluster.go b/cluster/cluster.go index 5077df5..a3c09b5 100644 --- a/cluster/cluster.go +++ b/cluster/cluster.go @@ -23,14 +23,14 @@ type Cluster struct { ml *memberlist.Memberlist mlConfig *memberlist.Config localNode common.Node - state *State + state *state events chan memberlist.NodeEvent } // New is used to create a new Cluster instance // The returned instance is ready to be updated with the local node settings then joined func New(init bool, clusterKey []byte, bindAddr string, bindPort int, useIPAsName bool) (*Cluster, error) { - state := &State{} + state := &state{} if !init { loadState(state) } @@ -151,7 +151,7 @@ func (c *Cluster) setupDelegate() { c.mlConfig.Events = &memberlist.ChannelEventDelegate{Ch: c.events} } -func computeClusterKey(state *State, clusterKey []byte) ([]byte, error) { +func computeClusterKey(state *state, clusterKey []byte) ([]byte, error) { if len(clusterKey) == 0 { clusterKey = state.ClusterKey } diff --git a/cluster/state.go b/cluster/state.go index df1f2ec..97db1c4 100644 --- a/cluster/state.go +++ b/cluster/state.go @@ -11,7 +11,7 @@ import ( ) // State keeps track of information needed to rejoin the cluster -type State struct { +type state struct { ClusterKey []byte Nodes []common.Node } @@ -31,7 +31,7 @@ func (c *Cluster) saveState() error { return ioutil.WriteFile(statePath, stateOut, 0600) } -func loadState(cs *State) { +func loadState(cs *state) { content, err := ioutil.ReadFile(statePath) if err != nil { if !os.IsNotExist(err) { @@ -41,7 +41,7 @@ func loadState(cs *State) { } // avoid partially unmarshalled content by using a temp var - csTmp := &State{} + csTmp := &state{} if err := json.Unmarshal(content, csTmp); err != nil { logrus.Warnf("could not decode state: %s", err) } else { diff --git a/cluster/state_test.go b/cluster/state_test.go index af2bcb4..840f58b 100644 --- a/cluster/state_test.go +++ b/cluster/state_test.go @@ -8,7 +8,7 @@ import ( "github.com/costela/wesher/common" ) -func Test_State_Save_Load(t *testing.T) { +func Test_state_save_soad(t *testing.T) { key := "abcdefghijklmnopqrstuvwxyzABCDEF" node := common.Node{ Name: "node", @@ -16,14 +16,14 @@ func Test_State_Save_Load(t *testing.T) { } cluster := Cluster{ - state: &State{ + state: &state{ ClusterKey: []byte(key), Nodes: []common.Node{node}, }, } cluster.saveState() - loaded := &State{} + loaded := &state{} loadState(loaded) if !reflect.DeepEqual(cluster.state, loaded) {