all: use Go 1.26 things, run most gofix modernizers
I omitted a lot of the min/max modernizers because they didn't result in more clear code. Some of it's older "for x := range 123". Also: errors.AsType, any, fmt.Appendf, etc. Updates #18682 Change-Id: I83a451577f33877f962766a5b65ce86f7696471c Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
committed by
Brad Fitzpatrick
parent
4453cc5f53
commit
bd2a2d53d3
@@ -69,7 +69,7 @@ func TestProtoUnmarshalText(t *testing.T) {
|
||||
|
||||
for i := range 256 {
|
||||
var p Proto
|
||||
must.Do(p.UnmarshalText([]byte(fmt.Sprintf("%d", i))))
|
||||
must.Do(p.UnmarshalText(fmt.Appendf(nil, "%d", i)))
|
||||
if got, want := p, Proto(i); got != want {
|
||||
t.Errorf("Proto(%d) = %v, want %v", i, got, want)
|
||||
}
|
||||
@@ -122,7 +122,7 @@ func TestProtoUnmarshalJSON(t *testing.T) {
|
||||
var p Proto
|
||||
|
||||
for i := range 256 {
|
||||
j := []byte(fmt.Sprintf(`%d`, i))
|
||||
j := fmt.Appendf(nil, `%d`, i)
|
||||
must.Do(json.Unmarshal(j, &p))
|
||||
if got, want := p, Proto(i); got != want {
|
||||
t.Errorf("Proto(%d) = %v, want %v", i, got, want)
|
||||
@@ -130,7 +130,7 @@ func TestProtoUnmarshalJSON(t *testing.T) {
|
||||
}
|
||||
|
||||
for name, wantProto := range acceptedNames {
|
||||
must.Do(json.Unmarshal([]byte(fmt.Sprintf(`"%s"`, name)), &p))
|
||||
must.Do(json.Unmarshal(fmt.Appendf(nil, `"%s"`, name), &p))
|
||||
if got, want := p, wantProto; got != want {
|
||||
t.Errorf("Proto(%q) = %v, want %v", name, got, want)
|
||||
}
|
||||
|
||||
@@ -145,13 +145,11 @@ func TestDeferredInit(t *testing.T) {
|
||||
// Call [DeferredInit.Do] concurrently.
|
||||
const N = 10000
|
||||
for range N {
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
wg.Go(func() {
|
||||
gotErr := di.Do()
|
||||
checkError(t, gotErr, nil, false)
|
||||
checkCalls()
|
||||
wg.Done()
|
||||
}()
|
||||
})
|
||||
}
|
||||
wg.Wait()
|
||||
})
|
||||
@@ -193,12 +191,10 @@ func TestDeferredErr(t *testing.T) {
|
||||
var wg sync.WaitGroup
|
||||
N := 10000
|
||||
for range N {
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
wg.Go(func() {
|
||||
gotErr := di.Do()
|
||||
checkError(t, gotErr, tt.wantErr, false)
|
||||
wg.Done()
|
||||
}()
|
||||
})
|
||||
}
|
||||
wg.Wait()
|
||||
})
|
||||
@@ -254,11 +250,9 @@ func TestDeferAfterDo(t *testing.T) {
|
||||
const N = 10000
|
||||
var wg sync.WaitGroup
|
||||
for range N {
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
wg.Go(func() {
|
||||
deferOnce()
|
||||
wg.Done()
|
||||
}()
|
||||
})
|
||||
}
|
||||
|
||||
if err := di.Do(); err != nil {
|
||||
|
||||
@@ -34,7 +34,7 @@ func TestMapResponseContainsNonPatchFields(t *testing.T) {
|
||||
return reflect.ValueOf(int64(1)).Convert(t)
|
||||
case reflect.Slice:
|
||||
return reflect.MakeSlice(t, 1, 1)
|
||||
case reflect.Ptr:
|
||||
case reflect.Pointer:
|
||||
return reflect.New(t.Elem())
|
||||
case reflect.Map:
|
||||
return reflect.MakeMap(t)
|
||||
@@ -43,8 +43,7 @@ func TestMapResponseContainsNonPatchFields(t *testing.T) {
|
||||
}
|
||||
|
||||
rt := reflect.TypeFor[tailcfg.MapResponse]()
|
||||
for i := range rt.NumField() {
|
||||
f := rt.Field(i)
|
||||
for f := range rt.Fields() {
|
||||
|
||||
var want bool
|
||||
switch f.Name {
|
||||
|
||||
@@ -12,8 +12,8 @@ import (
|
||||
)
|
||||
|
||||
func fieldsOf(t reflect.Type) (fields []string) {
|
||||
for i := range t.NumField() {
|
||||
if name := t.Field(i).Name; name != "_" {
|
||||
for field := range t.Fields() {
|
||||
if name := field.Name; name != "_" {
|
||||
fields = append(fields, name)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -968,8 +968,8 @@ func containsPointers(typ reflect.Type) bool {
|
||||
if isWellKnownImmutableStruct(typ) {
|
||||
return false
|
||||
}
|
||||
for i := range typ.NumField() {
|
||||
if containsPointers(typ.Field(i).Type) {
|
||||
for field := range typ.Fields() {
|
||||
if containsPointers(field.Type) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user