From bfa6b9dcef7592e6dd8225aaa0d0ab5aef5b3f84 Mon Sep 17 00:00:00 2001 From: Dave Henderson Date: Sun, 9 Mar 2025 20:14:46 -0400 Subject: chore(refactoring): Refactor/modernizations (#2345) chore(refactoring): Refactor with modernization refactorings * range over int * replace interface{} with any * replace common map operations with maps.Copy/maps.Clone * simplifying loops with slices.Contains/ContainsFunc * modernize benchmarks with b.Loop * modernize tests with t.Context * use fmt.Appendf * range over strings.SplitSeq * use new stdlib crypto/pbkdf2 package --------- Signed-off-by: Dave Henderson --- net/net.go | 12 ++---------- net/net_test.go | 4 ++-- 2 files changed, 4 insertions(+), 12 deletions(-) (limited to 'net') diff --git a/net/net.go b/net/net.go index d20a96dd..79b0dc4e 100644 --- a/net/net.go +++ b/net/net.go @@ -3,6 +3,7 @@ package net import ( "net" + "slices" ) // LookupIP - @@ -30,7 +31,7 @@ func LookupIPs(name string) ([]string, error) { for _, v := range srcIPs { if v.To4() != nil { s := v.String() - if !contains(ips, s) { + if !slices.Contains(ips, s) { ips = append(ips, s) } } @@ -38,15 +39,6 @@ func LookupIPs(name string) ([]string, error) { return ips, nil } -func contains(a []string, s string) bool { - for _, v := range a { - if v == s { - return true - } - } - return false -} - // LookupCNAME - func LookupCNAME(name string) (string, error) { return net.LookupCNAME(name) diff --git a/net/net_test.go b/net/net_test.go index 49f6db7d..a7d59baa 100644 --- a/net/net_test.go +++ b/net/net_test.go @@ -7,7 +7,7 @@ import ( "github.com/stretchr/testify/require" ) -func must(r interface{}, err error) interface{} { +func must(r any, err error) any { if err != nil { panic(err) } @@ -25,7 +25,7 @@ func TestLookupIPs(t *testing.T) { } func BenchmarkLookupIPs(b *testing.B) { - for i := 0; i < b.N; i++ { + for b.Loop() { must(LookupIPs("localhost")) } } -- cgit v1.2.3