From 40478cb534a95f37ca487c4c295000fba4e5c35d Mon Sep 17 00:00:00 2001 From: Sam Boyer Date: Tue, 26 May 2015 21:30:14 -0400 Subject: [PATCH 1/2] Condense switch fallthroughs into expr lists --- command/agent/command.go | 8 +------- consul/client.go | 4 +--- consul/fsm.go | 4 +--- consul/serf.go | 8 ++------ 4 files changed, 5 insertions(+), 19 deletions(-) diff --git a/command/agent/command.go b/command/agent/command.go index e27b9bb476..137c5387e6 100644 --- a/command/agent/command.go +++ b/command/agent/command.go @@ -638,13 +638,7 @@ func (c *Command) Run(args []string) int { c.Ui.Output(update.Op) c.Ui.Info(fmt.Sprintf("%.2f%%", update.Progress)) - case update.Progress-lastProgress >= 5: - fallthrough - - case time.Now().Sub(lastFlush) > time.Second: - fallthrough - - case update.Progress == 100: + case update.Progress-lastProgress >= 5, time.Now().Sub(lastFlush) > time.Second, update.Progress == 100: lastFlush = time.Now() lastProgress = update.Progress c.Ui.Info(fmt.Sprintf("%.2f%%", update.Progress)) diff --git a/consul/client.go b/consul/client.go index 1a61841a7b..8089bb4621 100644 --- a/consul/client.go +++ b/consul/client.go @@ -224,9 +224,7 @@ func (c *Client) lanEventHandler() { switch e.EventType() { case serf.EventMemberJoin: c.nodeJoin(e.(serf.MemberEvent)) - case serf.EventMemberLeave: - fallthrough - case serf.EventMemberFailed: + case serf.EventMemberLeave, serf.EventMemberFailed: c.nodeFail(e.(serf.MemberEvent)) case serf.EventUser: c.localEvent(e.(serf.UserEvent)) diff --git a/consul/fsm.go b/consul/fsm.go index d12e81578c..7324a72bc3 100644 --- a/consul/fsm.go +++ b/consul/fsm.go @@ -230,9 +230,7 @@ func (c *consulFSM) applyACLOperation(buf []byte, index uint64) interface{} { } defer metrics.MeasureSince([]string{"consul", "fsm", "acl", string(req.Op)}, time.Now()) switch req.Op { - case structs.ACLForceSet: - fallthrough - case structs.ACLSet: + case structs.ACLForceSet, structs.ACLSet: if err := c.state.ACLSet(index, &req.ACL); err != nil { return err } else { diff --git a/consul/serf.go b/consul/serf.go index e18f15cc6e..ed80a74b0a 100644 --- a/consul/serf.go +++ b/consul/serf.go @@ -41,9 +41,7 @@ func (s *Server) lanEventHandler() { s.nodeJoin(e.(serf.MemberEvent), false) s.localMemberEvent(e.(serf.MemberEvent)) - case serf.EventMemberLeave: - fallthrough - case serf.EventMemberFailed: + case serf.EventMemberLeave, serf.EventMemberFailed: s.nodeFailed(e.(serf.MemberEvent), false) s.localMemberEvent(e.(serf.MemberEvent)) @@ -71,9 +69,7 @@ func (s *Server) wanEventHandler() { switch e.EventType() { case serf.EventMemberJoin: s.nodeJoin(e.(serf.MemberEvent), true) - case serf.EventMemberLeave: - fallthrough - case serf.EventMemberFailed: + case serf.EventMemberLeave, serf.EventMemberFailed: s.nodeFailed(e.(serf.MemberEvent), true) case serf.EventMemberUpdate: // Ignore case serf.EventMemberReap: // Ignore From f37e2514d8bfc02182d399aadeb50aff4e6a19d0 Mon Sep 17 00:00:00 2001 From: Sam Boyer Date: Tue, 26 May 2015 21:43:41 -0400 Subject: [PATCH 2/2] Separate cases is better when its more verbose --- command/agent/command.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/command/agent/command.go b/command/agent/command.go index 137c5387e6..e27b9bb476 100644 --- a/command/agent/command.go +++ b/command/agent/command.go @@ -638,7 +638,13 @@ func (c *Command) Run(args []string) int { c.Ui.Output(update.Op) c.Ui.Info(fmt.Sprintf("%.2f%%", update.Progress)) - case update.Progress-lastProgress >= 5, time.Now().Sub(lastFlush) > time.Second, update.Progress == 100: + case update.Progress-lastProgress >= 5: + fallthrough + + case time.Now().Sub(lastFlush) > time.Second: + fallthrough + + case update.Progress == 100: lastFlush = time.Now() lastProgress = update.Progress c.Ui.Info(fmt.Sprintf("%.2f%%", update.Progress))