From e0ca8f20d27227e61e84bbd1a4b8a7efe48eb456 Mon Sep 17 00:00:00 2001 From: Xiang Li Date: Wed, 14 Aug 2013 15:20:25 -0700 Subject: [PATCH] add newJoinCommand func(). --- command.go | 8 ++++++++ raft_server.go | 17 +++-------------- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/command.go b/command.go index db117d69c..46da7329d 100644 --- a/command.go +++ b/command.go @@ -121,6 +121,14 @@ type JoinCommand struct { EtcdURL string `json:"etcdURL"` } +func newJoinCommand() *JoinCommand { + return &JoinCommand{ + Name: r.name, + RaftURL: r.url, + EtcdURL: e.url, + } +} + // The name of the join command in the log func (c *JoinCommand) CommandName() string { return commandName("join") diff --git a/raft_server.go b/raft_server.go index 80cf9e4c3..4984e303e 100644 --- a/raft_server.go +++ b/raft_server.go @@ -74,12 +74,7 @@ func (r *raftServer) start() { // leader need to join self as a peer for { - command := &JoinCommand{ - Name: r.name, - RaftURL: r.url, - EtcdURL: e.url, - } - _, err := server.Do(command) + _, err := server.Do(newJoinCommand()) if err == nil { break } @@ -173,13 +168,7 @@ func (r *raftServer) startTransport(scheme string, tlsConf tls.Config) { func joinCluster(s *raft.Server, raftURL string, scheme string) error { var b bytes.Buffer - command := &JoinCommand{ - Name: s.Name(), - RaftURL: r.url, - EtcdURL: e.url, - } - - json.NewEncoder(&b).Encode(command) + json.NewEncoder(&b).Encode(newJoinCommand()) // t must be ok t, ok := r.server.Transporter().(transporter) @@ -208,7 +197,7 @@ func joinCluster(s *raft.Server, raftURL string, scheme string) error { address := resp.Header.Get("Location") debugf("Send Join Request to %s", address) - json.NewEncoder(&b).Encode(command) + json.NewEncoder(&b).Encode(newJoinCommand()) resp, err = t.Post(address, &b)