From 4dfe45ec195c6d7f75fe9970cc872a05644feb5b Mon Sep 17 00:00:00 2001 From: Iskander Sharipov Date: Mon, 1 Oct 2018 12:07:19 +0300 Subject: [PATCH] app/router: rewrite if-else chain to switch MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From effective Go: https://golang.org/doc/effective_go.html#switch > It's therefore possible—and idiomatic—to write an if-else-if-else chain as a switch. --- app/router/config.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/app/router/config.go b/app/router/config.go index 56a709fb1..049dc65df 100644 --- a/app/router/config.go +++ b/app/router/config.go @@ -36,14 +36,15 @@ func cidrToCondition(cidr []*CIDR, source bool) (Condition, error) { } } - if !ipv4Net.IsEmpty() && hasIpv6 { + switch { + case !ipv4Net.IsEmpty() && hasIpv6: cond := NewAnyCondition() cond.Add(NewIPv4Matcher(ipv4Net, source)) cond.Add(ipv6Cond) return cond, nil - } else if !ipv4Net.IsEmpty() { + case !ipv4Net.IsEmpty(): return NewIPv4Matcher(ipv4Net, source), nil - } else { + default: return ipv6Cond, nil } }