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:
Brad Fitzpatrick
2026-03-05 21:13:57 +00:00
committed by Brad Fitzpatrick
parent 4453cc5f53
commit bd2a2d53d3
168 changed files with 431 additions and 618 deletions
+1 -1
View File
@@ -124,7 +124,7 @@ func ImportAliasCheck(t testing.TB, relDir string) {
}
badRx := regexp.MustCompile(`^([^:]+:\d+):\s+"golang\.org/x/exp/(slices|maps)"`)
if s := strings.TrimSpace(string(matches)); s != "" {
for _, line := range strings.Split(s, "\n") {
for line := range strings.SplitSeq(s, "\n") {
if m := badRx.FindStringSubmatch(line); m != nil {
t.Errorf("%s: the x/exp/%s package should be imported as x%s", m[1], m[2], m[2])
}
+1 -1
View File
@@ -1673,7 +1673,7 @@ func TestNetstackTCPLoopback(t *testing.T) {
defer lis.Close()
writeFn := func(conn net.Conn) error {
for i := 0; i < writeBufIterations; i++ {
for range writeBufIterations {
toWrite := make([]byte, writeBufSize)
var wrote int
for {
+2 -5
View File
@@ -317,9 +317,7 @@ func (nt *natTest) runTest(addNode ...addNodeFunc) pingRoute {
}
defer srv.Close()
wg.Add(1)
go func() {
defer wg.Done()
wg.Go(func() {
for {
c, err := srv.Accept()
if err != nil {
@@ -327,7 +325,7 @@ func (nt *natTest) runTest(addNode ...addNodeFunc) pingRoute {
}
go nt.vnet.ServeUnixConn(c.(*net.UnixConn), vnet.ProtocolQEMU)
}
}()
})
for i, node := range nodes {
disk := fmt.Sprintf("%s/node-%d.qcow2", nt.tempDir, i)
@@ -391,7 +389,6 @@ func (nt *natTest) runTest(addNode ...addNodeFunc) pingRoute {
var eg errgroup.Group
for i, c := range clients {
i, c := i, c
eg.Go(func() error {
node := nodes[i]
t.Logf("%v calling Status...", node)
+1 -1
View File
@@ -364,7 +364,7 @@ func (h *Harness) testDistro(t *testing.T, d Distro, ipm ipMapping) {
// starts with testcontrol sometimes there can be up to a few seconds where
// tailscaled is in an unknown state on these virtual machines. This exponential
// delay loop should delay long enough for tailscaled to be ready.
for count := 0; count < 10; count++ {
for range 10 {
sess := getSession(t, cli)
outp, err = sess.CombinedOutput("tailscale status")
+5 -11
View File
@@ -18,6 +18,7 @@ import (
"net"
"net/netip"
"os"
"slices"
"sort"
"strconv"
"sync"
@@ -247,12 +248,7 @@ func (f *Interface) String() string {
// Contains reports whether f contains ip as an IP.
func (f *Interface) Contains(ip netip.Addr) bool {
for _, v := range f.ips {
if ip == v {
return true
}
}
return false
return slices.Contains(f.ips, ip)
}
type routeEntry struct {
@@ -348,10 +344,8 @@ func (m *Machine) isLocalIP(ip netip.Addr) bool {
m.mu.Lock()
defer m.mu.Unlock()
for _, intf := range m.interfaces {
for _, iip := range intf.ips {
if ip == iip {
return true
}
if slices.Contains(intf.ips, ip) {
return true
}
}
return false
@@ -565,7 +559,7 @@ func (m *Machine) interfaceForIP(ip netip.Addr) (*Interface, error) {
func (m *Machine) pickEphemPort() (port uint16, err error) {
m.mu.Lock()
defer m.mu.Unlock()
for tries := 0; tries < 500; tries++ {
for range 500 {
port := uint16(rand.IntN(32<<10) + 32<<10)
if !m.portInUseLocked(port) {
return port, nil
+1 -1
View File
@@ -1917,7 +1917,7 @@ func (n *network) doPortMap(src netip.Addr, dstLANPort, wantExtPort uint16, sec
}
}
for try := 0; try < 20_000; try++ {
for range 20_000 {
if wanAP.Port() > 0 && !n.natTable.IsPublicPortUsed(wanAP) {
mak.Set(&n.portMap, wanAP, portMapping{
dst: dst,
+1 -1
View File
@@ -245,7 +245,7 @@ func TestParseGoroutines(t *testing.T) {
t.Errorf("sort field has different number of words: got %d, want %d", len(sorted), len(original))
continue
}
for i := 0; i < len(original); i++ {
for i := range original {
if original[i] != sorted[len(sorted)-1-i] {
t.Errorf("sort field word mismatch at position %d: got %q, want %q", i, sorted[len(sorted)-1-i], original[i])
}
+2 -3
View File
@@ -54,14 +54,13 @@ func MatchingPaths(rt reflect.Type, match func(reflect.Type) bool) iter.Seq[Path
return
}
switch t.Kind() {
case reflect.Ptr, reflect.Slice, reflect.Array:
case reflect.Pointer, reflect.Slice, reflect.Array:
walk(t.Elem(), func(root reflect.Value) reflect.Value {
v := getV(root)
return v.Elem()
})
case reflect.Struct:
for i := range t.NumField() {
sf := t.Field(i)
for sf := range t.Fields() {
fieldName := sf.Name
if fieldName == "_" {
continue