Skip to content

Commit 58498fc

Browse files
authored
Use the new map/slice features in Go 1.23 (#883)
Signed-off-by: Ziv Nevo <nevo@il.ibm.com>
1 parent d84416f commit 58498fc

File tree

4 files changed

+8
-25
lines changed

4 files changed

+8
-25
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/np-guard/vpc-network-config-analyzer
22

3-
go 1.22.4
3+
go 1.23.1
44

55
require (
66
github.com/IBM/networking-go-sdk v0.49.0

pkg/common/genericSet.go

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ package common
88

99
import (
1010
"fmt"
11+
"maps"
1112
"reflect"
13+
"slices"
1214
"sort"
1315
"strings"
1416
)
@@ -40,7 +42,7 @@ func (s GenericSet[T]) AsKey() SetAsKey {
4042
}
4143

4244
func (s GenericSet[T]) AsList() []T {
43-
return MapKeys(s)
45+
return slices.Collect(maps.Keys(s))
4446
}
4547

4648
func FromList[T comparable](l []T) GenericSet[T] {
@@ -74,23 +76,3 @@ func AnyMapEntry[K comparable, V any](m map[K]V) (k K, v V) {
7476
}
7577
return k, v
7678
}
77-
78-
// todo - these two methods will be available on go 1.23:
79-
func MapValues[K comparable, V any](m map[K]V) []V {
80-
vals := make([]V, len(m))
81-
i := 0
82-
for _, v := range m {
83-
vals[i] = v
84-
i++
85-
}
86-
return vals
87-
}
88-
func MapKeys[K comparable, V any](m map[K]V) []K {
89-
keys := make([]K, len(m))
90-
i := 0
91-
for k := range m {
92-
keys[i] = k
93-
i++
94-
}
95-
return keys
96-
}

pkg/drawio/layout.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ SPDX-License-Identifier: Apache-2.0
77
package drawio
88

99
import (
10+
"maps"
1011
"slices"
1112
"sort"
1213

@@ -466,7 +467,7 @@ func sortIconsBySGs(sgs []SquareTreeNodeInterface) [][]TreeNodeInterface {
466467
sgsToIcons[sgsAsKey] = append(sgsToIcons[sgsAsKey], icon)
467468
}
468469
// covert to list:
469-
return common.MapValues(sgsToIcons)
470+
return slices.Collect(maps.Values(sgsToIcons))
470471
}
471472

472473
// ///////////////////////////////////////////////////////////

pkg/linter/linterExecute.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ package linter
88

99
import (
1010
"fmt"
11+
"maps"
1112
"slices"
1213
"sort"
1314
"strings"
1415

15-
"github.com/np-guard/vpc-network-config-analyzer/pkg/common"
1616
"github.com/np-guard/vpc-network-config-analyzer/pkg/vpcmodel"
1717
)
1818

@@ -37,7 +37,7 @@ var linterGenerators = map[string]linterGenerator{
3737
}
3838

3939
func ValidLintersNames() string {
40-
return strings.Join(common.MapKeys(linterGenerators), ",")
40+
return strings.Join(slices.Collect(maps.Keys(linterGenerators)), ",")
4141
}
4242
func IsValidLintersNames(name string) bool {
4343
_, ok := linterGenerators[name]

0 commit comments

Comments
 (0)