diff options
author | Jakob Borg <jakob@kastelo.net> | 2024-02-10 21:02:42 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-02-10 21:02:42 +0100 |
commit | e1dd36561d51589a76c5db08664a7dbbc343382d (patch) | |
tree | 5462e219fca178dc315d2bcb4f55fa07dcb213a7 /lib | |
parent | 96c30f83870f12ad35477cf440cf57206324e0d3 (diff) | |
download | syncthing-e1dd36561d51589a76c5db08664a7dbbc343382d.tar.gz syncthing-e1dd36561d51589a76c5db08664a7dbbc343382d.zip |
all: Use some Go 1.21 features (#9409)
Diffstat (limited to 'lib')
-rw-r--r-- | lib/api/api_auth.go | 2 | ||||
-rw-r--r-- | lib/api/api_test.go | 2 | ||||
-rw-r--r-- | lib/api/tokenmanager.go | 2 | ||||
-rw-r--r-- | lib/connections/service.go | 21 | ||||
-rw-r--r-- | lib/locations/locations_test.go | 3 | ||||
-rw-r--r-- | lib/logger/logger.go | 3 | ||||
-rw-r--r-- | lib/model/queue_test.go | 2 | ||||
-rw-r--r-- | lib/nat/service.go | 15 | ||||
-rw-r--r-- | lib/protocol/vector.go | 7 | ||||
-rw-r--r-- | lib/sliceutil/sliceutil_test.go | 2 | ||||
-rw-r--r-- | lib/versioner/simple_test.go | 3 |
11 files changed, 12 insertions, 50 deletions
diff --git a/lib/api/api_auth.go b/lib/api/api_auth.go index cee0397ad..b24ad7950 100644 --- a/lib/api/api_auth.go +++ b/lib/api/api_auth.go @@ -11,6 +11,7 @@ import ( "fmt" "net" "net/http" + "slices" "strings" "time" @@ -19,7 +20,6 @@ import ( "github.com/syncthing/syncthing/lib/db" "github.com/syncthing/syncthing/lib/events" "github.com/syncthing/syncthing/lib/rand" - "golang.org/x/exp/slices" ) const ( diff --git a/lib/api/api_test.go b/lib/api/api_test.go index 9b053a340..8fac8a84d 100644 --- a/lib/api/api_test.go +++ b/lib/api/api_test.go @@ -18,6 +18,7 @@ import ( "net/http/httptest" "os" "path/filepath" + "slices" "strconv" "strings" "testing" @@ -46,7 +47,6 @@ import ( "github.com/syncthing/syncthing/lib/tlsutil" "github.com/syncthing/syncthing/lib/ur" "github.com/thejerf/suture/v4" - "golang.org/x/exp/slices" ) var ( diff --git a/lib/api/tokenmanager.go b/lib/api/tokenmanager.go index d03c75923..73ba8425e 100644 --- a/lib/api/tokenmanager.go +++ b/lib/api/tokenmanager.go @@ -7,12 +7,12 @@ package api import ( + "slices" "time" "github.com/syncthing/syncthing/lib/db" "github.com/syncthing/syncthing/lib/rand" "github.com/syncthing/syncthing/lib/sync" - "golang.org/x/exp/slices" ) type tokenManager struct { diff --git a/lib/connections/service.go b/lib/connections/service.go index c08a47c95..359dcff4d 100644 --- a/lib/connections/service.go +++ b/lib/connections/service.go @@ -22,14 +22,12 @@ import ( "math" "net" "net/url" + "slices" "sort" "strings" stdsync "sync" "time" - "golang.org/x/exp/constraints" - "golang.org/x/exp/slices" - "github.com/syncthing/syncthing/lib/build" "github.com/syncthing/syncthing/lib/config" "github.com/syncthing/syncthing/lib/connections/registry" @@ -1468,20 +1466,3 @@ func newConnectionID(t0, t1 int64) string { // from the random. We want the timestamp part deterministic. return enc.EncodeToString(buf[:8]) + enc.EncodeToString(buf[8:]) } - -// temporary implementations of min and max, to be removed once we can use -// Go 1.21 builtins. :) - -func min[T constraints.Ordered](a, b T) T { - if a < b { - return a - } - return b -} - -func max[T constraints.Ordered](a, b T) T { - if a > b { - return a - } - return b -} diff --git a/lib/locations/locations_test.go b/lib/locations/locations_test.go index 286476916..4c9208bf2 100644 --- a/lib/locations/locations_test.go +++ b/lib/locations/locations_test.go @@ -10,10 +10,9 @@ package locations import ( "path/filepath" + "slices" "testing" "time" - - "golang.org/x/exp/slices" ) func TestUnixConfigDir(t *testing.T) { diff --git a/lib/logger/logger.go b/lib/logger/logger.go index a60856e12..919a5fcf4 100644 --- a/lib/logger/logger.go +++ b/lib/logger/logger.go @@ -12,11 +12,10 @@ import ( "io" "log" "os" + "slices" "strings" "sync" "time" - - "golang.org/x/exp/slices" ) // This package uses stdlib sync as it may be used to debug syncthing/lib/sync diff --git a/lib/model/queue_test.go b/lib/model/queue_test.go index 34ff67fd8..a49f2c70f 100644 --- a/lib/model/queue_test.go +++ b/lib/model/queue_test.go @@ -9,11 +9,11 @@ package model import ( "fmt" "math/rand" + "slices" "testing" "time" "github.com/d4l3k/messagediff" - "golang.org/x/exp/slices" ) func TestJobQueue(t *testing.T) { diff --git a/lib/nat/service.go b/lib/nat/service.go index cc93e933a..8ff66a380 100644 --- a/lib/nat/service.go +++ b/lib/nat/service.go @@ -12,6 +12,7 @@ import ( "hash/fnv" "math/rand" "net" + "slices" stdsync "sync" "time" @@ -411,21 +412,11 @@ func addrSetsEqual(a []Address, b []Address) bool { return false } - // TODO: Rewrite this using slice.Contains once Go 1.21 is the minimum Go version. - for _, aElem := range a { - aElemFound := false - for _, bElem := range b { - if bElem.Equal(aElem) { - aElemFound = true - break - } - } - if !aElemFound { - // Found element in a that is not in b. + for _, v := range a { + if !slices.ContainsFunc(b, v.Equal) { return false } } - // b contains all elements of a and their lengths are equal, so the sets are equal. return true } diff --git a/lib/protocol/vector.go b/lib/protocol/vector.go index 74a8bd42a..fefb88aa9 100644 --- a/lib/protocol/vector.go +++ b/lib/protocol/vector.go @@ -43,13 +43,6 @@ func (v Vector) updateWithNow(id ShortID, now uint64) Vector { })} } -func max(a, b uint64) uint64 { - if a > b { - return a - } - return b -} - // Merge returns the vector containing the maximum indexes from v and b. If it // is possible, the vector v is updated and returned. If it is not, a copy // will be created, updated and returned. diff --git a/lib/sliceutil/sliceutil_test.go b/lib/sliceutil/sliceutil_test.go index 41387cd2b..cf3ecf711 100644 --- a/lib/sliceutil/sliceutil_test.go +++ b/lib/sliceutil/sliceutil_test.go @@ -7,10 +7,10 @@ package sliceutil_test import ( + "slices" "testing" "github.com/syncthing/syncthing/lib/sliceutil" - "golang.org/x/exp/slices" ) func TestRemoveAndZero(t *testing.T) { diff --git a/lib/versioner/simple_test.go b/lib/versioner/simple_test.go index 3b3abb436..5e540e48a 100644 --- a/lib/versioner/simple_test.go +++ b/lib/versioner/simple_test.go @@ -7,7 +7,6 @@ package versioner import ( - "math" "os" "path/filepath" "strings" @@ -88,7 +87,7 @@ func TestSimpleVersioningVersionCount(t *testing.T) { t.Error(err) } - if float64(len(n)) != math.Min(float64(i), 2) { + if len(n) != min(i, 2) { t.Error("Wrong count") } |