refactor: use better 'switch'

This commit is contained in:
Matthias Radestock committed 2014-09-22 22:34:46 +01:00
1 parent f11f84fe17
commit d5e797f695
4 files changed
+19 -19

No files matched your search

+5 -5
View File
@@ -182,14 +182,14 @@ func (conn *LocalConnection) queryLoop(queryChan <-chan *ConnectionInteraction,
if !ok {
break
}
switch {
case query.code == CShutdown:
switch query.code {
case CShutdown:
terminate = true
case query.code == CSetEstablished:
case CSetEstablished:
err = conn.handleSetEstablished()
case query.code == CSetRemoteUDPAddr:
case CSetRemoteUDPAddr:
err = conn.handleSetRemoteUDPAddr(query.payload.(*net.UDPAddr))
case query.code == CSendTCP:
case CSendTCP:
err = conn.handleSendTCP(query.payload.([]byte))
}
}
+6 -6
View File
@@ -16,8 +16,8 @@ const (
const (
CMInitiate = iota
CMStatus = iota
CMTerminated = iota
CMStatus = iota
)
func StartConnectionMaker(router *Router) *ConnectionMaker {
@@ -64,20 +64,20 @@ func (cm *ConnectionMaker) queryLoop(queryChan <-chan *ConnectionMakerInteractio
if !ok {
return
}
switch {
case query.code == CMInitiate:
switch query.code {
case CMInitiate:
cm.cmdLineAddress[NormalisePeerAddr(query.address)] = true
cm.checkStateAndAttemptConnections()
maybeTick()
case query.code == CMStatus:
query.resultChan <- cm.status()
case query.code == CMTerminated:
case CMTerminated:
if target, found := cm.targets[query.address]; found {
target.attempting = false
target.tryAfter, target.tryInterval = tryAfter(target.tryInterval)
}
cm.checkStateAndAttemptConnections()
maybeTick()
case CMStatus:
query.resultChan <- cm.status()
default:
log.Fatal("Unexpected connection maker query:", query)
}
+5 -5
View File
@@ -259,15 +259,15 @@ func (peer *Peer) queryLoop(queryChan <-chan *PeerInteraction) {
if !ok {
return
}
switch {
case query.code == PAddConnection:
switch query.code {
case PAddConnection:
peer.handleAddConnection(query.payload.(*LocalConnection))
case query.code == PDeleteConnection:
case PDeleteConnection:
peer.handleDeleteConnection(query.payload.(*LocalConnection))
query.resultChan <- nil
case query.code == PConnectionEstablished:
case PConnectionEstablished:
peer.handleConnectionEstablished(query.payload.(*LocalConnection))
case query.code == PBroadcastTCP:
case PBroadcastTCP:
peer.handleBroadcastTCP(query.payload.([]byte))
}
}
+3 -3
View File
@@ -81,15 +81,15 @@ func (topo *Topology) queryLoop(queryChan <-chan *Interaction) {
if !ok {
return
}
switch {
case query.code == TRebuildRoutes:
switch query.code {
case TRebuildRoutes:
unicast := topo.buildUnicastRoutes()
broadcast := topo.buildBroadcastRoutes()
topo.Lock()
topo.unicast = unicast
topo.broadcast = broadcast
topo.Unlock()
case query.code == TFetchAll:
case TFetchAll:
query.resultChan <- topo.router.Peers.EncodeAllPeers()
default:
log.Fatal("Unexpected topology query:", query)