all: update to Go 1.20, use strings.CutPrefix/Suffix instead of our fork

Updates #7123
Updates #5309

Change-Id: I90bcd87a2fb85a91834a0dd4be6e03db08438672
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
Brad Fitzpatrick
2023-02-01 13:43:06 -08:00
committed by Brad Fitzpatrick
parent 623176ebc9
commit b1248442c3
34 changed files with 73 additions and 147 deletions
+2 -2
View File
@@ -1001,11 +1001,11 @@ func FuzzTime(f *testing.F) {
) {
t1 := time.Unix(s1, ns1)
if loc1 {
t1.In(time.FixedZone(name1, off1))
_ = t1.In(time.FixedZone(name1, off1))
}
t2 := time.Unix(s2, ns2)
if loc2 {
t2.In(time.FixedZone(name2, off2))
_ = t2.In(time.FixedZone(name2, off2))
}
got := Hash(&t1) == Hash(&t2)
want := t1.Format(time.RFC3339Nano) == t2.Format(time.RFC3339Nano)
-35
View File
@@ -1,35 +0,0 @@
// Copyright (c) Tailscale Inc & AUTHORS
// SPDX-License-Identifier: BSD-3-Clause
// Package strs contains string-related utility funcs.
package strs
import "strings"
// CutPrefix returns s without the provided leading prefix string
// and reports whether it found the prefix.
// If s doesn't start with prefix, CutPrefix returns s, false.
// If prefix is the empty string, CutPrefix returns s, true.
//
// TODO: remove this once Go 1.20 is out with it.
// See https://github.com/tailscale/tailscale/issues/5309
func CutPrefix(s, prefix string) (after string, found bool) {
if !strings.HasPrefix(s, prefix) {
return s, false
}
return s[len(prefix):], true
}
// CutSuffix returns s without the provided ending suffix string
// and reports whether it found the suffix.
// If s doesn't end with suffix, CutSuffix returns s, false.
// If suffix is the empty string, CutSuffix returns s, true.
//
// See https://github.com/tailscale/tailscale/issues/5309
// TODO: remove this once Go 1.20 is out with it.
func CutSuffix(s, suffix string) (before string, found bool) {
if !strings.HasSuffix(s, suffix) {
return s, false
}
return s[:len(s)-len(suffix)], true
}
-29
View File
@@ -1,29 +0,0 @@
// Copyright (c) Tailscale Inc & AUTHORS
// SPDX-License-Identifier: BSD-3-Clause
package strs
import "testing"
func TestCut(t *testing.T) {
tests := []struct {
fn func(string, string) (string, bool)
in1, in2 string
want string
wantOK bool
}{
{CutPrefix, "foo", "fo", "o", true},
{CutPrefix, "bar", "fo", "bar", false},
{CutSuffix, "foo", "o", "fo", true},
{CutSuffix, "bar", "fo", "bar", false},
}
for i, tt := range tests {
got, gotOK := tt.fn(tt.in1, tt.in2)
if got != tt.want {
t.Errorf("%d. got %q; want %q", i, got, tt.want)
}
if gotOK != tt.wantOK {
t.Errorf("%d. got %v; want %v", i, gotOK, tt.wantOK)
}
}
}