Skip to content

Commit 350eff4

Browse files
committed
run modernize -fix ./...
1 parent 0efdd61 commit 350eff4

File tree

5 files changed

+24
-38
lines changed

5 files changed

+24
-38
lines changed

internal/agent/f5/as3/as3_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ func TestGetServiceTenants(t *testing.T) {
120120
Label: "",
121121
Remark: "",
122122
Template: "shared",
123-
Services: map[string]interface{}{
123+
Services: map[string]any{
124124
"pool-test-service-id": Pool{
125125
Class: "Pool",
126126
Label: "service-test-service-id",
@@ -151,6 +151,6 @@ func TestGetServiceTenants(t *testing.T) {
151151
}
152152

153153
func TestGetServiceTenantsWithoutServices(t *testing.T) {
154-
expected := Tenant{Class: "Tenant", Label: "", Remark: "", Applications: map[string]Application{"Shared": {Class: "Application", Label: "", Remark: "", Template: "shared", Services: map[string]interface{}{}}}}
154+
expected := Tenant{Class: "Tenant", Label: "", Remark: "", Applications: map[string]Application{"Shared": {Class: "Application", Label: "", Remark: "", Template: "shared", Services: map[string]any{}}}}
155155
assert.EqualValues(t, expected, GetServiceTenants([]*ExtendedService{}))
156156
}

internal/agent/f5/bigip/bigip.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"fmt"
1010
"net/url"
1111
"os"
12+
"slices"
1213
"strings"
1314
"time"
1415

@@ -240,11 +241,9 @@ func (b *BigIP) EnsureGuestVlan(segmentId int) error {
240241
for _, deviceHost := range config.Global.Agent.Devices {
241242
if strings.HasSuffix(deviceHost, guest.Hostname) {
242243
vlanName := fmt.Sprintf("/Common/vlan-%d", segmentId)
243-
for _, vlan := range guest.Vlans {
244-
if vlan == vlanName {
245-
// found, nothing to do
246-
return nil
247-
}
244+
if slices.Contains(guest.Vlans, vlanName) {
245+
// found, nothing to do
246+
return nil
248247
}
249248
newGuest := bigip.VcmpGuest{Vlans: internal.Unique(append(guest.Vlans, vlanName))}
250249
return (*bigip.BigIP)(b).UpdateVcmpGuest(guest.Name, &newGuest)

internal/agent/f5/f5os/f5os.go

Lines changed: 16 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
"net/http"
1717
"net/url"
1818
"os"
19+
"slices"
1920
"strings"
2021
"time"
2122

@@ -42,7 +43,7 @@ func (t token) Valid() bool {
4243
return false
4344
}
4445

45-
var payload map[string]interface{}
46+
var payload map[string]any
4647
if err = json.Unmarshal(decoded, &payload); err != nil {
4748
log.Errorf("error unmarshalling JWT payload: %v", err)
4849
return false
@@ -223,15 +224,13 @@ func (f *F5OS) EnsureInterfaceVlan(segmentID int) error {
223224
return fmt.Errorf("error fetching trunk VLANs: %w", err)
224225
}
225226

226-
for _, v := range vlans.OpenconfigVlanTrunkVlans {
227-
if v == segmentID {
228-
log.WithFields(log.Fields{
229-
"host": f.GetHostname(),
230-
"segmentID": segmentID,
231-
"interface": config.Global.Agent.PhysicalInterface,
232-
}).Debug("Trunk VLAN already exists")
233-
return nil
234-
}
227+
if slices.Contains(vlans.OpenconfigVlanTrunkVlans, segmentID) {
228+
log.WithFields(log.Fields{
229+
"host": f.GetHostname(),
230+
"segmentID": segmentID,
231+
"interface": config.Global.Agent.PhysicalInterface,
232+
}).Debug("Trunk VLAN already exists")
233+
return nil
235234
}
236235

237236
vlans.OpenconfigVlanTrunkVlans = append(vlans.OpenconfigVlanTrunkVlans, segmentID)
@@ -249,23 +248,19 @@ func (f *F5OS) EnsureGuestVlan(segmentId int) error {
249248
return fmt.Errorf("error getTenant: %w", err)
250249
}
251250

252-
for _, v := range tenant.State.Vlans {
253-
if v == segmentId {
254-
log.WithField("host", f.GetHostname()).
255-
Debugf("Guest VLAN %d already exists on tenant %s", segmentId, tenant.Name)
256-
return nil
257-
}
251+
if slices.Contains(tenant.State.Vlans, segmentId) {
252+
log.WithField("host", f.GetHostname()).
253+
Debugf("Guest VLAN %d already exists on tenant %s", segmentId, tenant.Name)
254+
return nil
258255
}
259256

260257
path := fmt.Sprintf("api/data/f5-tenants:tenants/tenant=%s/config/vlans", tenant.Name)
261258
existingVlans := F5TenantVlans{
262259
F5TenantsVlans: tenant.State.Vlans,
263260
}
264261

265-
for _, v := range existingVlans.F5TenantsVlans {
266-
if v == segmentId {
267-
return nil
268-
}
262+
if slices.Contains(existingVlans.F5TenantsVlans, segmentId) {
263+
return nil
269264
}
270265

271266
existingVlans.F5TenantsVlans = append(existingVlans.F5TenantsVlans, segmentId)
@@ -316,15 +311,7 @@ func (f *F5OS) SyncGuestVLANs(usedSegments map[int]string) error {
316311
}
317312

318313
for _, vid := range tenant.State.Vlans {
319-
managed := false
320-
for _, vlanName := range VlanNames {
321-
if fmt.Sprintf("vlan-%d", vid) == vlanName {
322-
managed = true
323-
break
324-
}
325-
}
326-
327-
if !managed {
314+
if !slices.Contains(VlanNames, fmt.Sprintf("vlan-%d", vid)) {
328315
// it is a management VLAN, keep it
329316
updatedVlans = append(updatedVlans, vid)
330317
continue

internal/agent/f5/f5os/openconfig_vlan.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ type vlan struct {
1717
} `json:"config"`
1818
Members struct {
1919
Member []member `json:"member,omitempty"`
20-
} `json:"members,omitempty"`
20+
} `json:"members"`
2121
}
2222

2323
type trunkVlans struct {

internal/client/table_writer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func getRow(row reflect.Value, iMap [][]int) table.Row {
4141
}
4242

4343
r := make([]any, 0)
44-
for i := 0; i < len(iMap); i++ {
44+
for i := range iMap {
4545
r = append(r, formatValue(reflectx.FieldByIndexes(row, iMap[i])))
4646
}
4747
return r

0 commit comments

Comments
 (0)