瀏覽代碼

Merge pull request #1293 from Quasilyte/quasilyte/ifElseChain

app/router: rewrite if-else chain to switch
Victoria Raymond 7 年之前
父節點
當前提交
504eff5fe4
共有 1 個文件被更改,包括 4 次插入3 次删除
  1. 4 3
      app/router/config.go

+ 4 - 3
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
 	}
 }