mirror of
https://github.com/v2fly/v2ray-core.git
synced 2024-09-26 05:46:10 -04:00
app/router: rewrite if-else chain to switch
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.
This commit is contained in:
parent
091fa6ad23
commit
4dfe45ec19
@ -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
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user