Skip to content

Commit 004837a

Browse files
committed
lint: backend/core_iptree.go
1 parent dffca1f commit 004837a

1 file changed

Lines changed: 26 additions & 24 deletions

File tree

intra/backend/core_iptree.go

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,14 @@ type iptree struct {
6464
}
6565

6666
const (
67-
Vsep = "," // Vsep is a values separator (csv)
68-
Ksep = "," // Ksep is a key separator (csv)
69-
Kdelim = "@" // Kdelim is a key@csv(v) delimiter
70-
KVsep = "|" // KVsep is a k1:v1|k2:v2 separator
67+
// Vsep is a values separator (csv)
68+
Vsep = ","
69+
// Ksep is a key separator (csv)
70+
Ksep = ","
71+
// Kdelim is a key@csv(v) delimiter
72+
Kdelim = "@"
73+
// KVsep is a k1:v1|k2:v2 separator
74+
KVsep = "|"
7175
)
7276

7377
var (
@@ -80,7 +84,9 @@ func NewIpTree() IpTree {
8084
}
8185

8286
func (c *iptree) Add(cidr string, v string) error {
83-
if x, err := c.Get(cidr); err != nil {
87+
x, err := c.Get(cidr)
88+
89+
if err != nil {
8490
return err
8591
} else if len(v) == 0 || x == v {
8692
return nil
@@ -94,9 +100,8 @@ func (c *iptree) Add(cidr string, v string) error {
94100
}
95101
} // v is not in x, but something resembling ~v was.
96102
return c.Set(cidr, x+Vsep+v)
97-
} else {
98-
return c.Set(cidr, x+Vsep+v)
99103
}
104+
return c.Set(cidr, x+Vsep+v)
100105
}
101106

102107
func (c *iptree) Set(cidr string, v string) error {
@@ -144,9 +149,8 @@ func (c *iptree) Esc(cidr string, v string) bool {
144149
return c.Del(cidr)
145150
}
146151
return c.Set(cidr, strings.Join(cur, Vsep)) == nil
147-
} else {
148-
return false
149152
}
153+
return false
150154
}
151155

152156
func (c *iptree) Has(cidr string) (bool, error) {
@@ -227,16 +231,16 @@ func (c *iptree) GetAny(cidr string) (rv string, err error) {
227231
c.RLock()
228232
defer c.RUnlock()
229233

230-
if m, v, err := c.t.Match(r); err != nil {
234+
m, v, err := c.t.Match(r)
235+
if err != nil {
231236
return "", err
232-
} else {
233-
if m != nil {
234-
rv = m.String()
235-
}
236-
if v != nil {
237-
if s, ok := v.(string); ok {
238-
rv = rv + Kdelim + s
239-
}
237+
}
238+
if m != nil {
239+
rv = m.String()
240+
}
241+
if v != nil {
242+
if s, ok := v.(string); ok {
243+
rv = rv + Kdelim + s
240244
}
241245
}
242246
return
@@ -277,7 +281,7 @@ func (c *iptree) Routes(cidr string) string {
277281
defer c.RUnlock()
278282

279283
rt := make([]string, 0)
280-
c.t.WalkMatch(r, func(k *net.IPNet, v any) bool {
284+
c.t.WalkMatch(r, func(k *net.IPNet, _ any) bool {
281285
if k != nil {
282286
rt = append(rt, k.String())
283287
}
@@ -296,7 +300,7 @@ func (c *iptree) Values(cidr string) string {
296300
defer c.RUnlock()
297301

298302
vt := make([]string, 0)
299-
c.t.WalkMatch(r, func(k *net.IPNet, v any) bool {
303+
c.t.WalkMatch(r, func(_ *net.IPNet, v any) bool {
300304
if v != nil {
301305
if s, ok := v.(string); ok && len(s) > 0 {
302306
vt = append(vt, s)
@@ -337,9 +341,8 @@ func (c *iptree) EscLike(cidr, like string) int32 {
337341
_ = c.Set(cidr, strings.Join(cur, Vsep))
338342
}
339343
return n
340-
} else {
341-
return 0 // not found
342344
}
345+
return 0 // not found
343346
}
344347

345348
func (c *iptree) GetLike(cidr, like string) string {
@@ -359,9 +362,8 @@ func (c *iptree) GetLike(cidr, like string) string {
359362
}
360363
}
361364
return strings.Join(grab, Vsep)
362-
} else {
363-
return "" // not found
364365
}
366+
return "" // not found
365367
}
366368

367369
func (c *iptree) RoutesLike(cidr, like string) string {

0 commit comments

Comments
 (0)