From e50fe39d9404f587840e0e0a2877609eb43b5988 Mon Sep 17 00:00:00 2001 From: Jes Cok Date: Tue, 30 Apr 2024 00:20:33 +0800 Subject: [PATCH] pkg/netutil: avoid type conversion between uint8 and int for GetDefaultHost Signed-off-by: Jes Cok --- pkg/netutil/routes_linux.go | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/pkg/netutil/routes_linux.go b/pkg/netutil/routes_linux.go index 163063550c5..03f97bd5d2d 100644 --- a/pkg/netutil/routes_linux.go +++ b/pkg/netutil/routes_linux.go @@ -21,7 +21,7 @@ import ( "encoding/binary" "fmt" "net" - "sort" + "slices" "syscall" "go.etcd.io/etcd/pkg/v3/cpuutil" @@ -48,14 +48,13 @@ func GetDefaultHost() (string, error) { } // sort so choice is deterministic - var families []int + var families []uint8 for family := range rmsgs { - families = append(families, int(family)) + families = append(families, family) } - sort.Ints(families) + slices.Sort(families) - for _, f := range families { - family := uint8(f) + for _, family := range families { if host, err := chooseHost(family, rmsgs[family]); host != "" || err != nil { return host, err }