From 088b1d1a93fd866ab1f136a8985c55c58b34ee90 Mon Sep 17 00:00:00 2001 From: Josh Deprez Date: Fri, 26 Apr 2024 14:37:38 +1000 Subject: [PATCH] Switch for enums --- atalk/nbp/nbp.go | 18 ++++++++++++------ router/peer.go | 42 ++++++++++++++++++++++++++++-------------- 2 files changed, 40 insertions(+), 20 deletions(-) diff --git a/atalk/nbp/nbp.go b/atalk/nbp/nbp.go index 20acd90..423533d 100644 --- a/atalk/nbp/nbp.go +++ b/atalk/nbp/nbp.go @@ -36,12 +36,18 @@ const ( ) func (f Function) String() string { - return map[Function]string{ - FunctionBrRq: "BrRq", - FunctionLkUp: "LkUp", - FunctionLkUpReply: "LkUp-Reply", - FunctionFwdReq: "FwdReq", - }[f] + switch f { + case FunctionBrRq: + return "BrRq" + case FunctionLkUp: + return "LkUp" + case FunctionLkUpReply: + return "LkUp-Reply" + case FunctionFwdReq: + return "FwdReq" + default: + return "unknown" + } } // Packet represents an NBP packet. diff --git a/router/peer.go b/router/peer.go index 0016ade..cf50e9c 100644 --- a/router/peer.go +++ b/router/peer.go @@ -48,13 +48,20 @@ const ( ) func (rs receiverState) String() string { - return map[receiverState]string{ - rsUnconnected: "unconnected", - rsConnected: "connected", - rsWaitForOpenRsp: "waiting for Open-Rsp", - rsWaitForRIRsp: "waiting for RI-Rsp", - rsWaitForTickleAck: "waiting for Tickle-Ack", - }[rs] + switch rs { + case rsUnconnected: + return "unconnected" + case rsConnected: + return "connected" + case rsWaitForOpenRsp: + return "waiting for Open-Rsp" + case rsWaitForRIRsp: + return "waiting for RI-Rsp" + case rsWaitForTickleAck: + return "waiting for Tickle-Ack" + default: + return "unknown" + } } type senderState int @@ -68,13 +75,20 @@ const ( ) func (ss senderState) String() string { - return map[senderState]string{ - ssUnconnected: "unconnected", - ssConnected: "connected", - ssWaitForRIRspAck: "waiting for RI-Ack for RI-Rsp", - ssWaitForRIUpdAck: "waiting for RI-Ack for RI-Upd", - ssWaitForRDAck: "waiting for RI-Ack for RD", - }[ss] + switch ss { + case ssUnconnected: + return "unconnected" + case ssConnected: + return "connected" + case ssWaitForRIRspAck: + return "waiting for RI-Ack for RI-Rsp" + case ssWaitForRIUpdAck: + return "waiting for RI-Ack for RI-Upd" + case ssWaitForRDAck: + return "waiting for RI-Ack for RD" + default: + return "unknown" + } } type Peer struct {