From 0868329936835f60264c6057f742d0234b317b96 Mon Sep 17 00:00:00 2001 From: Josh Bleecher Snyder Date: Wed, 16 Mar 2022 16:27:57 -0700 Subject: [PATCH] all: use any instead of interface{} My favorite part of generics. Signed-off-by: Josh Bleecher Snyder --- chirp/chirp.go | 2 +- cmd/cloner/cloner.go | 6 +++--- cmd/derpprobe/derpprobe.go | 6 +++--- cmd/tailscale/cli/cert.go | 2 +- cmd/tailscale/cli/cli.go | 8 ++++---- cmd/tailscale/cli/status.go | 2 +- cmd/tailscale/cli/up.go | 10 +++++----- cmd/tailscale/cli/web.go | 2 +- cmd/testcontrol/testcontrol.go | 16 +++++++-------- control/controlclient/auto.go | 2 +- control/controlclient/direct.go | 10 +++++----- derp/derp_server.go | 20 +++++++++---------- derp/derp_test.go | 2 +- envknob/envknob.go | 2 +- ipn/ipnlocal/peerapi.go | 2 +- ipn/ipnlocal/ssh.go | 2 +- ipn/ipnlocal/state_test.go | 2 +- ipn/ipnserver/server_test.go | 4 ++-- ipn/ipnstate/ipnstate.go | 2 +- ipn/localapi/cert.go | 4 ++-- ipn/localapi/localapi.go | 2 +- ipn/message_test.go | 4 ++-- ipn/prefs.go | 2 +- kube/client.go | 2 +- log/filelogger/log.go | 2 +- logpolicy/logpolicy.go | 2 +- logtail/logtail.go | 4 ++-- logtail/logtail_test.go | 6 +++--- net/dns/manager_linux_test.go | 2 +- net/dns/nm.go | 4 ++-- net/dns/resolved.go | 2 +- net/dns/resolver/tsdns.go | 2 +- net/dns/resolver/tsdns_server_test.go | 4 ++-- net/dns/resolver/tsdns_test.go | 4 ++-- net/dnscache/dnscache.go | 2 +- net/dnscache/messagecache.go | 2 +- net/dnscache/messagecache_test.go | 6 +++--- net/flowtrack/flowtrack.go | 6 +++--- net/flowtrack/flowtrack_test.go | 2 +- net/netcheck/netcheck.go | 4 ++-- net/netcheck/netcheck_test.go | 4 ++-- net/portmapper/disabled_stubs.go | 2 +- net/portmapper/igd_test.go | 2 +- net/socks5/socks5.go | 2 +- net/tstun/wrap.go | 2 +- packages/deb/deb_test.go | 2 +- ssh/tailssh/context.go | 2 +- ssh/tailssh/incubator_linux.go | 6 +++--- tailcfg/tailcfg_clone.go | 2 +- tstest/integration/testcontrol/testcontrol.go | 10 +++++----- tstest/log.go | 4 ++-- tstest/natlab/natlab.go | 6 +++--- tsweb/debug.go | 8 ++++---- tsweb/debug_test.go | 4 ++-- tsweb/jsonhandler.go | 8 ++++---- tsweb/jsonhandler_test.go | 20 +++++++++---------- tsweb/tsweb.go | 16 +++++++-------- tsweb/tsweb_test.go | 12 +++++------ types/dnstype/dnstype_clone.go | 2 +- types/logger/logger.go | 20 +++++++++---------- types/logger/logger_test.go | 6 +++--- types/logger/rusage.go | 2 +- types/opt/bool.go | 2 +- types/opt/bool_test.go | 2 +- util/clientmetric/clientmetric.go | 2 +- util/codegen/codegen.go | 2 +- util/deephash/deephash.go | 8 ++++---- util/deephash/deephash_test.go | 12 +++++------ util/jsonutil/unmarshal.go | 6 +++--- util/jsonutil/unmarshal_test.go | 6 +++--- util/multierr/multierr.go | 2 +- util/systemd/systemd_linux.go | 4 ++-- util/systemd/systemd_nonlinux.go | 4 ++-- util/uniq/slice.go | 2 +- wf/firewall.go | 6 +++--- wgengine/filter/filter_test.go | 2 +- wgengine/magicsock/magicsock.go | 2 +- wgengine/magicsock/magicsock_test.go | 4 ++-- wgengine/monitor/monitor.go | 2 +- wgengine/monitor/monitor_darwin.go | 2 +- wgengine/netstack/netstack_test.go | 2 +- wgengine/router/router_linux.go | 2 +- wgengine/router/router_windows.go | 2 +- wgengine/watchdog.go | 4 ++-- wgengine/watchdog_test.go | 2 +- wgengine/wgcfg/parser_test.go | 2 +- wgengine/wglog/wglog.go | 4 ++-- wgengine/wglog/wglog_test.go | 8 ++++---- 88 files changed, 204 insertions(+), 204 deletions(-) diff --git a/chirp/chirp.go b/chirp/chirp.go index d465ab7de..3c4342281 100644 --- a/chirp/chirp.go +++ b/chirp/chirp.go @@ -80,7 +80,7 @@ func (b *BIRDClient) EnableProtocol(protocol string) error { // Reply codes starting with 0 stand for ‘action successfully completed’ messages, // 1 means ‘table entry’, 8 ‘runtime error’ and 9 ‘syntax error’. -func (b *BIRDClient) exec(cmd string, args ...interface{}) (string, error) { +func (b *BIRDClient) exec(cmd string, args ...any) (string, error) { if _, err := fmt.Fprintf(b.conn, cmd, args...); err != nil { return "", err } diff --git a/cmd/cloner/cloner.go b/cmd/cloner/cloner.go index a825dc214..2e4520a95 100644 --- a/cmd/cloner/cloner.go +++ b/cmd/cloner/cloner.go @@ -69,14 +69,14 @@ func main() { gen(buf, imports, typ, pkg.Types) } - w := func(format string, args ...interface{}) { + w := func(format string, args ...any) { fmt.Fprintf(buf, format+"\n", args...) } if *flagCloneFunc { w("// Clone duplicates src into dst and reports whether it succeeded.") w("// To succeed, must be of types <*T, *T> or <*T, **T>,") w("// where T is one of %s.", *flagTypes) - w("func Clone(dst, src interface{}) bool {") + w("func Clone(dst, src any) bool {") w(" switch src := src.(type) {") for _, typeName := range typeNames { w(" case *%s:", typeName) @@ -158,7 +158,7 @@ func gen(buf *bytes.Buffer, imports map[string]struct{}, typ *types.Named, thisP fmt.Fprintf(buf, "// Clone makes a deep copy of %s.\n", name) fmt.Fprintf(buf, "// The result aliases no memory with the original.\n") fmt.Fprintf(buf, "func (src *%s) Clone() *%s {\n", name, name) - writef := func(format string, args ...interface{}) { + writef := func(format string, args ...any) { fmt.Fprintf(buf, "\t"+format+"\n", args...) } writef("if src == nil {") diff --git a/cmd/derpprobe/derpprobe.go b/cmd/derpprobe/derpprobe.go index ca389aa38..07660f8c7 100644 --- a/cmd/derpprobe/derpprobe.go +++ b/cmd/derpprobe/derpprobe.go @@ -78,11 +78,11 @@ type overallStatus struct { good, bad []string } -func (st *overallStatus) addBadf(format string, a ...interface{}) { +func (st *overallStatus) addBadf(format string, a ...any) { st.bad = append(st.bad, fmt.Sprintf(format, a...)) } -func (st *overallStatus) addGoodf(format string, a ...interface{}) { +func (st *overallStatus) addGoodf(format string, a ...any) { st.good = append(st.good, fmt.Sprintf(format, a...)) } @@ -426,7 +426,7 @@ func probeNodePair(ctx context.Context, dm *tailcfg.DERPMap, from, to *tailcfg.D } // Receive the random packet. - recvc := make(chan interface{}, 1) // either derp.ReceivedPacket or error + recvc := make(chan any, 1) // either derp.ReceivedPacket or error go func() { for { m, err := toc.Recv() diff --git a/cmd/tailscale/cli/cert.go b/cmd/tailscale/cli/cert.go index 38007c173..ac7284d8f 100644 --- a/cmd/tailscale/cli/cert.go +++ b/cmd/tailscale/cli/cert.go @@ -79,7 +79,7 @@ func runCert(ctx context.Context, args []string) error { } domain := args[0] - printf := func(format string, a ...interface{}) { + printf := func(format string, a ...any) { printf(format, a...) } if certArgs.certFile == "-" || certArgs.keyFile == "-" { diff --git a/cmd/tailscale/cli/cli.go b/cmd/tailscale/cli/cli.go index e70a67ab9..93ea0c60e 100644 --- a/cmd/tailscale/cli/cli.go +++ b/cmd/tailscale/cli/cli.go @@ -35,7 +35,7 @@ import ( var Stderr io.Writer = os.Stderr var Stdout io.Writer = os.Stdout -func printf(format string, a ...interface{}) { +func printf(format string, a ...any) { fmt.Fprintf(Stdout, format, a...) } @@ -44,7 +44,7 @@ func printf(format string, a ...interface{}) { // // It's not named println because that looks like the Go built-in // which goes to stderr and formats slightly differently. -func outln(a ...interface{}) { +func outln(a ...any) { fmt.Fprintln(Stdout, a...) } @@ -216,7 +216,7 @@ change in the future. return err } -func fatalf(format string, a ...interface{}) { +func fatalf(format string, a ...any) { if Fatalf != nil { Fatalf(format, a...) return @@ -226,7 +226,7 @@ func fatalf(format string, a ...interface{}) { } // Fatalf, if non-nil, is used instead of log.Fatalf. -var Fatalf func(format string, a ...interface{}) +var Fatalf func(format string, a ...any) var rootArgs struct { socket string diff --git a/cmd/tailscale/cli/status.go b/cmd/tailscale/cli/status.go index 73b3f320e..d4241e374 100644 --- a/cmd/tailscale/cli/status.go +++ b/cmd/tailscale/cli/status.go @@ -136,7 +136,7 @@ func runStatus(ctx context.Context, args []string) error { } var buf bytes.Buffer - f := func(format string, a ...interface{}) { fmt.Fprintf(&buf, format, a...) } + f := func(format string, a ...any) { fmt.Fprintf(&buf, format, a...) } printPS := func(ps *ipnstate.PeerStatus) { f("%-15s %-20s %-12s %-7s ", firstIPString(ps.TailscaleIPs), diff --git a/cmd/tailscale/cli/up.go b/cmd/tailscale/cli/up.go index 91436f808..4b495f41e 100644 --- a/cmd/tailscale/cli/up.go +++ b/cmd/tailscale/cli/up.go @@ -192,7 +192,7 @@ type upOutputJSON struct { Error string `json:",omitempty"` // description of an error } -func warnf(format string, args ...interface{}) { +func warnf(format string, args ...any) { printf("Warning: "+format+"\n", args...) } @@ -823,8 +823,8 @@ func flagAppliesToOS(flag, goos string) bool { return true } -func prefsToFlags(env upCheckEnv, prefs *ipn.Prefs) (flagVal map[string]interface{}) { - ret := make(map[string]interface{}) +func prefsToFlags(env upCheckEnv, prefs *ipn.Prefs) (flagVal map[string]any) { + ret := make(map[string]any) exitNodeIPStr := func() string { if !prefs.ExitNodeIP.IsZero() { @@ -841,7 +841,7 @@ func prefsToFlags(env upCheckEnv, prefs *ipn.Prefs) (flagVal map[string]interfac if preflessFlag(f.Name) { return } - set := func(v interface{}) { + set := func(v any) { if flagAppliesToOS(f.Name, env.goos) { ret[f.Name] = v } else { @@ -895,7 +895,7 @@ func prefsToFlags(env upCheckEnv, prefs *ipn.Prefs) (flagVal map[string]interfac return ret } -func fmtFlagValueArg(flagName string, val interface{}) string { +func fmtFlagValueArg(flagName string, val any) string { if val == true { return "--" + flagName } diff --git a/cmd/tailscale/cli/web.go b/cmd/tailscale/cli/web.go index 3f4e188df..b8e2fac07 100644 --- a/cmd/tailscale/cli/web.go +++ b/cmd/tailscale/cli/web.go @@ -313,7 +313,7 @@ func webHandler(w http.ResponseWriter, r *http.Request) { AdvertiseExitNode bool Reauthenticate bool } - type mi map[string]interface{} + type mi map[string]any if err := json.NewDecoder(r.Body).Decode(&postData); err != nil { w.WriteHeader(400) json.NewEncoder(w).Encode(mi{"error": err.Error()}) diff --git a/cmd/testcontrol/testcontrol.go b/cmd/testcontrol/testcontrol.go index 116badd24..f4c1534b9 100644 --- a/cmd/testcontrol/testcontrol.go +++ b/cmd/testcontrol/testcontrol.go @@ -46,10 +46,10 @@ type fakeTB struct { } func (t fakeTB) Cleanup(_ func()) {} -func (t fakeTB) Error(args ...interface{}) { +func (t fakeTB) Error(args ...any) { t.Fatal(args...) } -func (t fakeTB) Errorf(format string, args ...interface{}) { +func (t fakeTB) Errorf(format string, args ...any) { t.Fatalf(format, args...) } func (t fakeTB) Fail() { @@ -61,17 +61,17 @@ func (t fakeTB) FailNow() { func (t fakeTB) Failed() bool { return false } -func (t fakeTB) Fatal(args ...interface{}) { +func (t fakeTB) Fatal(args ...any) { log.Fatal(args...) } -func (t fakeTB) Fatalf(format string, args ...interface{}) { +func (t fakeTB) Fatalf(format string, args ...any) { log.Fatalf(format, args...) } func (t fakeTB) Helper() {} -func (t fakeTB) Log(args ...interface{}) { +func (t fakeTB) Log(args ...any) { log.Print(args...) } -func (t fakeTB) Logf(format string, args ...interface{}) { +func (t fakeTB) Logf(format string, args ...any) { log.Printf(format, args...) } func (t fakeTB) Name() string { @@ -80,13 +80,13 @@ func (t fakeTB) Name() string { func (t fakeTB) Setenv(key string, value string) { panic("not implemented") } -func (t fakeTB) Skip(args ...interface{}) { +func (t fakeTB) Skip(args ...any) { t.Fatal("skipped") } func (t fakeTB) SkipNow() { t.Fatal("skipnow") } -func (t fakeTB) Skipf(format string, args ...interface{}) { +func (t fakeTB) Skipf(format string, args ...any) { t.Logf(format, args...) t.Fatal("skipped") } diff --git a/control/controlclient/auto.go b/control/controlclient/auto.go index cecf95c60..87066d628 100644 --- a/control/controlclient/auto.go +++ b/control/controlclient/auto.go @@ -92,7 +92,7 @@ func NewNoStart(opts Options) (*Auto, error) { return nil, err } if opts.Logf == nil { - opts.Logf = func(fmt string, args ...interface{}) {} + opts.Logf = func(fmt string, args ...any) {} } if opts.TimeNow == nil { opts.TimeNow = time.Now diff --git a/control/controlclient/direct.go b/control/controlclient/direct.go index 1d0496e6a..8aafee2d1 100644 --- a/control/controlclient/direct.go +++ b/control/controlclient/direct.go @@ -945,7 +945,7 @@ func (c *Direct) sendMapRequest(ctx context.Context, maxPolls int, cb func(*netm // decode JSON decodes the res.Body into v. If serverNoiseKey is not specified, // it uses the serverKey and mkey to decode the message from the NaCl-crypto-box. -func decode(res *http.Response, v interface{}, serverKey, serverNoiseKey key.MachinePublic, mkey key.MachinePrivate) error { +func decode(res *http.Response, v any, serverKey, serverNoiseKey key.MachinePublic, mkey key.MachinePrivate) error { defer res.Body.Close() msg, err := ioutil.ReadAll(io.LimitReader(res.Body, 1<<20)) if err != nil { @@ -970,7 +970,7 @@ var jsonEscapedZero = []byte(`\u0000`) // decodeMsg is responsible for uncompressing msg and unmarshaling into v. // If c.serverNoiseKey is not specified, it uses the c.serverKey and mkey // to first the decrypt msg from the NaCl-crypto-box. -func (c *Direct) decodeMsg(msg []byte, v interface{}, mkey key.MachinePrivate) error { +func (c *Direct) decodeMsg(msg []byte, v any, mkey key.MachinePrivate) error { c.mu.Lock() serverKey := c.serverKey serverNoiseKey := c.serverNoiseKey @@ -1016,7 +1016,7 @@ func (c *Direct) decodeMsg(msg []byte, v interface{}, mkey key.MachinePrivate) e } -func decodeMsg(msg []byte, v interface{}, serverKey key.MachinePublic, machinePrivKey key.MachinePrivate) error { +func decodeMsg(msg []byte, v any, serverKey key.MachinePublic, machinePrivKey key.MachinePrivate) error { decrypted, ok := machinePrivKey.OpenFrom(serverKey, msg) if !ok { return errors.New("cannot decrypt response") @@ -1032,7 +1032,7 @@ func decodeMsg(msg []byte, v interface{}, serverKey key.MachinePublic, machinePr // encode JSON encodes v. If serverNoiseKey is not specified, it uses the serverKey and mkey to // seal the message into a NaCl-crypto-box. -func encode(v interface{}, serverKey, serverNoiseKey key.MachinePublic, mkey key.MachinePrivate) ([]byte, error) { +func encode(v any, serverKey, serverNoiseKey key.MachinePublic, mkey key.MachinePrivate) ([]byte, error) { b, err := json.Marshal(v) if err != nil { return nil, err @@ -1310,7 +1310,7 @@ func (c *Direct) getNoiseClient() (*noiseClient, error) { if nc != nil { return nc, nil } - np, err, _ := c.sfGroup.Do("noise", func() (interface{}, error) { + np, err, _ := c.sfGroup.Do("noise", func() (any, error) { k, err := c.getMachinePrivKey() if err != nil { return nil, err diff --git a/derp/derp_server.go b/derp/derp_server.go index 9d522ece9..5e73cb8c8 100644 --- a/derp/derp_server.go +++ b/derp/derp_server.go @@ -1641,8 +1641,8 @@ func (m multiForwarder) ForwardPacket(src, dst key.NodePublic, payload []byte) e return fwd.ForwardPacket(src, dst, payload) } -func (s *Server) expVarFunc(f func() interface{}) expvar.Func { - return expvar.Func(func() interface{} { +func (s *Server) expVarFunc(f func() any) expvar.Func { + return expvar.Func(func() any { s.mu.Lock() defer s.mu.Unlock() return f() @@ -1652,14 +1652,14 @@ func (s *Server) expVarFunc(f func() interface{}) expvar.Func { // ExpVar returns an expvar variable suitable for registering with expvar.Publish. func (s *Server) ExpVar() expvar.Var { m := new(metrics.Set) - m.Set("gauge_memstats_sys0", expvar.Func(func() interface{} { return int64(s.memSys0) })) - m.Set("gauge_watchers", s.expVarFunc(func() interface{} { return len(s.watchers) })) - m.Set("gauge_current_file_descriptors", expvar.Func(func() interface{} { return metrics.CurrentFDs() })) + m.Set("gauge_memstats_sys0", expvar.Func(func() any { return int64(s.memSys0) })) + m.Set("gauge_watchers", s.expVarFunc(func() any { return len(s.watchers) })) + m.Set("gauge_current_file_descriptors", expvar.Func(func() any { return metrics.CurrentFDs() })) m.Set("gauge_current_connections", &s.curClients) m.Set("gauge_current_home_connections", &s.curHomeClients) - m.Set("gauge_clients_total", expvar.Func(func() interface{} { return len(s.clientsMesh) })) - m.Set("gauge_clients_local", expvar.Func(func() interface{} { return len(s.clients) })) - m.Set("gauge_clients_remote", expvar.Func(func() interface{} { return len(s.clientsMesh) - len(s.clients) })) + m.Set("gauge_clients_total", expvar.Func(func() any { return len(s.clientsMesh) })) + m.Set("gauge_clients_local", expvar.Func(func() any { return len(s.clients) })) + m.Set("gauge_clients_remote", expvar.Func(func() any { return len(s.clientsMesh) - len(s.clients) })) m.Set("gauge_current_dup_client_keys", &s.dupClientKeys) m.Set("gauge_current_dup_client_conns", &s.dupClientConns) m.Set("counter_total_dup_client_conns", &s.dupClientConnTotal) @@ -1683,7 +1683,7 @@ func (s *Server) ExpVar() expvar.Var { m.Set("multiforwarder_created", &s.multiForwarderCreated) m.Set("multiforwarder_deleted", &s.multiForwarderDeleted) m.Set("packet_forwarder_delete_other_value", &s.removePktForwardOther) - m.Set("average_queue_duration_ms", expvar.Func(func() interface{} { + m.Set("average_queue_duration_ms", expvar.Func(func() any { return math.Float64frombits(atomic.LoadUint64(s.avgQueueDuration)) })) var expvarVersion expvar.String @@ -1813,7 +1813,7 @@ func (s *Server) ServeDebugTraffic(w http.ResponseWriter, r *http.Request) { } var bufioWriterPool = &sync.Pool{ - New: func() interface{} { + New: func() any { return bufio.NewWriterSize(ioutil.Discard, 2<<10) }, } diff --git a/derp/derp_test.go b/derp/derp_test.go index b16add71a..0b8da1f9d 100644 --- a/derp/derp_test.go +++ b/derp/derp_test.go @@ -802,7 +802,7 @@ func TestClientRecv(t *testing.T) { tests := []struct { name string input []byte - want interface{} + want any }{ { name: "ping", diff --git a/envknob/envknob.go b/envknob/envknob.go index db0e9ae77..fe38aca5f 100644 --- a/envknob/envknob.go +++ b/envknob/envknob.go @@ -46,7 +46,7 @@ func noteEnv(k, v string) { // logf is logger.Logf, but logger depends on envknob, so for circular // dependency reasons, make a type alias (so it's still assignable, // but has nice docs here). -type logf = func(format string, args ...interface{}) +type logf = func(format string, args ...any) // LogCurrent logs the currently set environment knobs. func LogCurrent(logf logf) { diff --git a/ipn/ipnlocal/peerapi.go b/ipn/ipnlocal/peerapi.go index 36770d7ab..91b906542 100644 --- a/ipn/ipnlocal/peerapi.go +++ b/ipn/ipnlocal/peerapi.go @@ -519,7 +519,7 @@ type peerAPIHandler struct { peerUser tailcfg.UserProfile // profile of peerNode } -func (h *peerAPIHandler) logf(format string, a ...interface{}) { +func (h *peerAPIHandler) logf(format string, a ...any) { h.ps.b.logf("peerapi: "+format, a...) } diff --git a/ipn/ipnlocal/ssh.go b/ipn/ipnlocal/ssh.go index 87f303127..8689fe2d4 100644 --- a/ipn/ipnlocal/ssh.go +++ b/ipn/ipnlocal/ssh.go @@ -83,7 +83,7 @@ func (b *LocalBackend) hostKeyFileOrCreate(keyDir, typ string) ([]byte, error) { if !os.IsNotExist(err) { return nil, err } - var priv interface{} + var priv any switch typ { default: return nil, fmt.Errorf("unsupported key type %q", typ) diff --git a/ipn/ipnlocal/state_test.go b/ipn/ipnlocal/state_test.go index ba3fb5c22..db6398387 100644 --- a/ipn/ipnlocal/state_test.go +++ b/ipn/ipnlocal/state_test.go @@ -107,7 +107,7 @@ func newMockControl(tb testing.TB) *mockControl { } } -func (cc *mockControl) logf(format string, args ...interface{}) { +func (cc *mockControl) logf(format string, args ...any) { if cc.preventLog.Get() || cc.logfActual == nil { return } diff --git a/ipn/ipnserver/server_test.go b/ipn/ipnserver/server_test.go index cea794bac..3580164ec 100644 --- a/ipn/ipnserver/server_test.go +++ b/ipn/ipnserver/server_test.go @@ -28,7 +28,7 @@ func TestRunMultipleAccepts(t *testing.T) { td := t.TempDir() socketPath := filepath.Join(td, "tailscale.sock") - logf := func(format string, args ...interface{}) { + logf := func(format string, args ...any) { format = strings.TrimRight(format, "\n") println(fmt.Sprintf(format, args...)) t.Logf(format, args...) @@ -52,7 +52,7 @@ func TestRunMultipleAccepts(t *testing.T) { } } - logTriggerTestf := func(format string, args ...interface{}) { + logTriggerTestf := func(format string, args ...any) { logf(format, args...) if strings.HasPrefix(format, "Listening on ") { connect() diff --git a/ipn/ipnstate/ipnstate.go b/ipn/ipnstate/ipnstate.go index 401bccee9..9c103d379 100644 --- a/ipn/ipnstate/ipnstate.go +++ b/ipn/ipnstate/ipnstate.go @@ -342,7 +342,7 @@ type StatusUpdater interface { } func (st *Status) WriteHTML(w io.Writer) { - f := func(format string, args ...interface{}) { fmt.Fprintf(w, format, args...) } + f := func(format string, args ...any) { fmt.Fprintf(w, format, args...) } f(` diff --git a/ipn/localapi/cert.go b/ipn/localapi/cert.go index 5ae12f97f..a2506f173 100644 --- a/ipn/localapi/cert.go +++ b/ipn/localapi/cert.go @@ -85,7 +85,7 @@ func (h *Handler) serveCert(w http.ResponseWriter, r *http.Request) { now := time.Now() logf := logger.WithPrefix(h.logf, fmt.Sprintf("cert(%q): ", domain)) - traceACME := func(v interface{}) { + traceACME := func(v any) { if !acmeDebug { return } @@ -164,7 +164,7 @@ func (h *Handler) getCertPEMCached(dir, domain string, now time.Time) (p *keyPai return nil, false } -func (h *Handler) getCertPEM(ctx context.Context, logf logger.Logf, traceACME func(interface{}), dir, domain string, now time.Time) (*keyPair, error) { +func (h *Handler) getCertPEM(ctx context.Context, logf logger.Logf, traceACME func(any), dir, domain string, now time.Time) (*keyPair, error) { acmeMu.Lock() defer acmeMu.Unlock() diff --git a/ipn/localapi/localapi.go b/ipn/localapi/localapi.go index 11723989d..9d6fcae9d 100644 --- a/ipn/localapi/localapi.go +++ b/ipn/localapi/localapi.go @@ -557,7 +557,7 @@ func defBool(a string, def bool) bool { // (currently only a slice or a map) and makes sure it's non-nil for // JSON serialization. (In particular, JavaScript clients usually want // the field to be defined after they decode the JSON.) -func makeNonNil(ptr interface{}) { +func makeNonNil(ptr any) { if ptr == nil { panic("nil interface") } diff --git a/ipn/message_test.go b/ipn/message_test.go index 194ac3b89..e3b3b7d12 100644 --- a/ipn/message_test.go +++ b/ipn/message_test.go @@ -85,10 +85,10 @@ func TestClientServer(t *testing.T) { clientToServer := func(b []byte) { bs.GotCommandMsg(context.TODO(), b) } - slogf := func(fmt string, args ...interface{}) { + slogf := func(fmt string, args ...any) { t.Logf("s: "+fmt, args...) } - clogf := func(fmt string, args ...interface{}) { + clogf := func(fmt string, args ...any) { t.Logf("c: "+fmt, args...) } bs = NewBackendServer(slogf, b, serverToClient) diff --git a/ipn/prefs.go b/ipn/prefs.go index f7d34cf53..47a9b358d 100644 --- a/ipn/prefs.go +++ b/ipn/prefs.go @@ -42,7 +42,7 @@ var ( // IsLoginServerSynonym reports whether a URL is a drop-in replacement // for the primary Tailscale login server. -func IsLoginServerSynonym(val interface{}) bool { +func IsLoginServerSynonym(val any) bool { return val == "https://login.tailscale.com" || val == "https://controlplane.tailscale.com" } diff --git a/kube/client.go b/kube/client.go index 8bb8bc883..82e4684ee 100644 --- a/kube/client.go +++ b/kube/client.go @@ -110,7 +110,7 @@ func getError(resp *http.Response) error { return st } -func (c *Client) doRequest(ctx context.Context, method, url string, in, out interface{}) error { +func (c *Client) doRequest(ctx context.Context, method, url string, in, out any) error { tk, err := c.getOrRenewToken() if err != nil { return err diff --git a/log/filelogger/log.go b/log/filelogger/log.go index f8c4da65b..53cbeeefb 100644 --- a/log/filelogger/log.go +++ b/log/filelogger/log.go @@ -77,7 +77,7 @@ func dayOf(t time.Time) civilDay { return civilDay{t.Year(), t.Month(), t.Day()} } -func (w *logFileWriter) Logf(format string, a ...interface{}) { +func (w *logFileWriter) Logf(format string, a ...any) { w.mu.Lock() defer w.mu.Unlock() diff --git a/logpolicy/logpolicy.go b/logpolicy/logpolicy.go index 44ed235ed..696be98f2 100644 --- a/logpolicy/logpolicy.go +++ b/logpolicy/logpolicy.go @@ -416,7 +416,7 @@ func New(collection string) *Policy { console := log.New(stderrWriter{}, "", lflags) var earlyErrBuf bytes.Buffer - earlyLogf := func(format string, a ...interface{}) { + earlyLogf := func(format string, a ...any) { fmt.Fprintf(&earlyErrBuf, format, a...) earlyErrBuf.WriteByte('\n') } diff --git a/logtail/logtail.go b/logtail/logtail.go index 60921cd0a..e1c8f8863 100644 --- a/logtail/logtail.go +++ b/logtail/logtail.go @@ -515,7 +515,7 @@ func (l *Logger) encode(buf []byte, level int) []byte { now := l.timeNow() - obj := make(map[string]interface{}) + obj := make(map[string]any) if err := json.Unmarshal(buf, &obj); err != nil { for k := range obj { delete(obj, k) @@ -553,7 +553,7 @@ func (l *Logger) encode(buf []byte, level int) []byte { } // Logf logs to l using the provided fmt-style format and optional arguments. -func (l *Logger) Logf(format string, args ...interface{}) { +func (l *Logger) Logf(format string, args ...any) { fmt.Fprintf(l, format, args...) } diff --git a/logtail/logtail_test.go b/logtail/logtail_test.go index 82cbd924c..f5be19eae 100644 --- a/logtail/logtail_test.go +++ b/logtail/logtail_test.go @@ -128,7 +128,7 @@ func TestEncodeAndUploadMessages(t *testing.T) { ltail, ok := data["logtail"] if ok { - logtailmap := ltail.(map[string]interface{}) + logtailmap := ltail.(map[string]any) _, ok = logtailmap["client_time"] if !ok { t.Errorf("%s: no client_time present", tt.name) @@ -317,9 +317,9 @@ func TestPublicIDUnmarshalText(t *testing.T) { } } -func unmarshalOne(t *testing.T, body []byte) map[string]interface{} { +func unmarshalOne(t *testing.T, body []byte) map[string]any { t.Helper() - var entries []map[string]interface{} + var entries []map[string]any err := json.Unmarshal(body, &entries) if err != nil { t.Error(err) diff --git a/net/dns/manager_linux_test.go b/net/dns/manager_linux_test.go index 9f6c1e0c0..1826b76d9 100644 --- a/net/dns/manager_linux_test.go +++ b/net/dns/manager_linux_test.go @@ -258,7 +258,7 @@ func TestLinuxDNSMode(t *testing.T) { } } -type memFS map[string]interface{} // full path => string for regular files +type memFS map[string]any // full path => string for regular files func (m memFS) Stat(name string) (isRegular bool, err error) { v, ok := m[name] diff --git a/net/dns/nm.go b/net/dns/nm.go index 5733098d2..bd989b176 100644 --- a/net/dns/nm.go +++ b/net/dns/nm.go @@ -140,12 +140,12 @@ func (m *nmManager) trySet(ctx context.Context, config OSConfig) error { // NetworkManager wipes out IPv6 address configuration unless we // tell it explicitly to keep it. Read out the current interface // settings and mirror them out to NetworkManager. - var addrs6 []map[string]interface{} + var addrs6 []map[string]any addrs, _, err := interfaces.Tailscale() if err == nil { for _, a := range addrs { if a.Is6() { - addrs6 = append(addrs6, map[string]interface{}{ + addrs6 = append(addrs6, map[string]any{ "address": a.String(), "prefix": uint32(128), }) diff --git a/net/dns/resolved.go b/net/dns/resolved.go index 7faad3d1b..b731c7594 100644 --- a/net/dns/resolved.go +++ b/net/dns/resolved.go @@ -141,7 +141,7 @@ func (m *resolvedManager) resync(ctx context.Context, signals chan *dbus.Signal) if signal.Path != dbusPath || signal.Name != dbusInterface+"."+dbusOwnerSignal { continue } - // signal.Body is a []interface{} of 3 strings: bus name, previous owner, new owner. + // signal.Body is a []any of 3 strings: bus name, previous owner, new owner. if len(signal.Body) != 3 { m.logf("[unexpectected] DBus NameOwnerChanged len(Body) = %d, want 3") } diff --git a/net/dns/resolver/tsdns.go b/net/dns/resolver/tsdns.go index 9fd92fcfd..19576c91e 100644 --- a/net/dns/resolver/tsdns.go +++ b/net/dns/resolver/tsdns.go @@ -711,7 +711,7 @@ type response struct { } var dnsParserPool = &sync.Pool{ - New: func() interface{} { + New: func() any { return new(dnsParser) }, } diff --git a/net/dns/resolver/tsdns_server_test.go b/net/dns/resolver/tsdns_server_test.go index 1e5f0294b..db8eeea67 100644 --- a/net/dns/resolver/tsdns_server_test.go +++ b/net/dns/resolver/tsdns_server_test.go @@ -221,7 +221,7 @@ func weirdoGoCNAMEHandler(target string) dns.HandlerFunc { // provided. // // Types supported: netaddr.IP. -func dnsHandler(answers ...interface{}) dns.HandlerFunc { +func dnsHandler(answers ...any) dns.HandlerFunc { return func(w dns.ResponseWriter, req *dns.Msg) { m := new(dns.Msg) m.SetReply(req) @@ -303,7 +303,7 @@ func dnsHandler(answers ...interface{}) dns.HandlerFunc { } } -func serveDNS(tb testing.TB, addr string, records ...interface{}) *dns.Server { +func serveDNS(tb testing.TB, addr string, records ...any) *dns.Server { if len(records)%2 != 0 { panic("must have an even number of record values") } diff --git a/net/dns/resolver/tsdns_test.go b/net/dns/resolver/tsdns_test.go index 2bd21007c..1665c2373 100644 --- a/net/dns/resolver/tsdns_test.go +++ b/net/dns/resolver/tsdns_test.go @@ -454,7 +454,7 @@ func TestDelegate(t *testing.T) { // intend to handle responses this large, so there should be truncation. hugeTXT := generateTXT(64000, randSource) - records := []interface{}{ + records := []any{ "test.site.", resolveToIP(testipv4, testipv6, "dns.test.site."), "LCtesT.SiTe.", @@ -1105,7 +1105,7 @@ func TestHandleExitNodeDNSQueryWithNetPkg(t *testing.T) { t.Skip("skipping test on Windows; waiting for golang.org/issue/33097") } - records := []interface{}{ + records := []any{ "no-records.test.", dnsHandler(), diff --git a/net/dnscache/dnscache.go b/net/dnscache/dnscache.go index cf1ef5817..a04831306 100644 --- a/net/dnscache/dnscache.go +++ b/net/dnscache/dnscache.go @@ -129,7 +129,7 @@ func (r *Resolver) LookupIP(ctx context.Context, host string) (ip, v6 net.IP, al ip, ip6 net.IP allIPs []net.IPAddr } - ch := r.sf.DoChan(host, func() (interface{}, error) { + ch := r.sf.DoChan(host, func() (any, error) { ip, ip6, allIPs, err := r.lookupIP(host) if err != nil { return nil, err diff --git a/net/dnscache/messagecache.go b/net/dnscache/messagecache.go index cfdfc8a0f..5c93be7c5 100644 --- a/net/dnscache/messagecache.go +++ b/net/dnscache/messagecache.go @@ -103,7 +103,7 @@ type msgResource struct { var ErrCacheMiss = errors.New("cache miss") var parserPool = &sync.Pool{ - New: func() interface{} { return new(dnsmessage.Parser) }, + New: func() any { return new(dnsmessage.Parser) }, } // ReplyFromCache writes a DNS reply to w for the provided DNS query message, diff --git a/net/dnscache/messagecache_test.go b/net/dnscache/messagecache_test.go index be56aef6e..3a699f586 100644 --- a/net/dnscache/messagecache_test.go +++ b/net/dnscache/messagecache_test.go @@ -118,17 +118,17 @@ type responseOpt bool type ttlOpt uint32 -func makeQ(txID uint16, name string, opt ...interface{}) []byte { +func makeQ(txID uint16, name string, opt ...any) []byte { opt = append(opt, responseOpt(false)) return makeDNSPkt(txID, name, opt...) } -func makeRes(txID uint16, name string, opt ...interface{}) []byte { +func makeRes(txID uint16, name string, opt ...any) []byte { opt = append(opt, responseOpt(true)) return makeDNSPkt(txID, name, opt...) } -func makeDNSPkt(txID uint16, name string, opt ...interface{}) []byte { +func makeDNSPkt(txID uint16, name string, opt ...any) []byte { typ := dnsmessage.TypeA class := dnsmessage.ClassINET var response bool diff --git a/net/flowtrack/flowtrack.go b/net/flowtrack/flowtrack.go index 4f660959b..427b80099 100644 --- a/net/flowtrack/flowtrack.go +++ b/net/flowtrack/flowtrack.go @@ -46,7 +46,7 @@ type Cache struct { // entry is the container/list element type. type entry struct { key Tuple - value interface{} + value any } // Add adds a value to the cache, set or updating its associated @@ -54,7 +54,7 @@ type entry struct { // // If MaxEntries is non-zero and the length of the cache is greater // after any addition, the least recently used value is evicted. -func (c *Cache) Add(key Tuple, value interface{}) { +func (c *Cache) Add(key Tuple, value any) { if c.m == nil { c.m = make(map[Tuple]*list.Element) c.ll = list.New() @@ -73,7 +73,7 @@ func (c *Cache) Add(key Tuple, value interface{}) { // Get looks up a key's value from the cache, also reporting // whether it was present. -func (c *Cache) Get(key Tuple) (value interface{}, ok bool) { +func (c *Cache) Get(key Tuple) (value any, ok bool) { if ele, hit := c.m[key]; hit { c.ll.MoveToFront(ele) return ele.Value.(*entry).value, true diff --git a/net/flowtrack/flowtrack_test.go b/net/flowtrack/flowtrack_test.go index 80288f334..4f00a6973 100644 --- a/net/flowtrack/flowtrack_test.go +++ b/net/flowtrack/flowtrack_test.go @@ -25,7 +25,7 @@ func TestCache(t *testing.T) { t.Fatalf("Len = %d; want %d", got, want) } } - wantVal := func(key Tuple, want interface{}) { + wantVal := func(key Tuple, want any) { t.Helper() got, ok := c.Get(key) if !ok { diff --git a/net/netcheck/netcheck.go b/net/netcheck/netcheck.go index 4aa007d30..18a87f4d8 100644 --- a/net/netcheck/netcheck.go +++ b/net/netcheck/netcheck.go @@ -191,7 +191,7 @@ func (c *Client) enoughRegions() int { return 3 } -func (c *Client) logf(format string, a ...interface{}) { +func (c *Client) logf(format string, a ...any) { if c.Logf != nil { c.Logf(format, a...) } else { @@ -199,7 +199,7 @@ func (c *Client) logf(format string, a ...interface{}) { } } -func (c *Client) vlogf(format string, a ...interface{}) { +func (c *Client) vlogf(format string, a ...any) { if c.Verbose || debugNetcheck { c.logf(format, a...) } diff --git a/net/netcheck/netcheck_test.go b/net/netcheck/netcheck_test.go index c99aad2cd..e14194073 100644 --- a/net/netcheck/netcheck_test.go +++ b/net/netcheck/netcheck_test.go @@ -119,7 +119,7 @@ func TestWorksWhenUDPBlocked(t *testing.T) { func TestAddReportHistoryAndSetPreferredDERP(t *testing.T) { // report returns a *Report from (DERP host, time.Duration)+ pairs. - report := func(a ...interface{}) *Report { + report := func(a ...any) *Report { r := &Report{RegionLatency: map[int]time.Duration{}} for i := 0; i < len(a); i += 2 { s := a[i].(string) @@ -606,7 +606,7 @@ func TestLogConciseReport(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { var buf bytes.Buffer - c := &Client{Logf: func(f string, a ...interface{}) { fmt.Fprintf(&buf, f, a...) }} + c := &Client{Logf: func(f string, a ...any) { fmt.Fprintf(&buf, f, a...) }} c.logConciseReport(tt.r, dm) if got := strings.TrimPrefix(buf.String(), "[v1] report: "); got != tt.want { t.Errorf("unexpected result.\n got: %#q\nwant: %#q\n", got, tt.want) diff --git a/net/portmapper/disabled_stubs.go b/net/portmapper/disabled_stubs.go index 641422acc..097424b3e 100644 --- a/net/portmapper/disabled_stubs.go +++ b/net/portmapper/disabled_stubs.go @@ -15,7 +15,7 @@ import ( "inet.af/netaddr" ) -type upnpClient interface{} +type upnpClient any type uPnPDiscoResponse struct{} diff --git a/net/portmapper/igd_test.go b/net/portmapper/igd_test.go index 110930d3f..d3f8e5f3e 100644 --- a/net/portmapper/igd_test.go +++ b/net/portmapper/igd_test.go @@ -67,7 +67,7 @@ func NewTestIGD(logf logger.Logf, t TestIGDOptions) (*TestIGD, error) { doPCP: t.PCP, doUPnP: t.UPnP, } - d.logf = func(msg string, args ...interface{}) { + d.logf = func(msg string, args ...any) { // Don't log after the device has closed; // stray trailing logging angers testing.T.Logf. if d.closed.Get() { diff --git a/net/socks5/socks5.go b/net/socks5/socks5.go index a5dfee820..32a05a3af 100644 --- a/net/socks5/socks5.go +++ b/net/socks5/socks5.go @@ -95,7 +95,7 @@ func (s *Server) dial(ctx context.Context, network, addr string) (net.Conn, erro return dial(ctx, network, addr) } -func (s *Server) logf(format string, args ...interface{}) { +func (s *Server) logf(format string, args ...any) { logf := s.Logf if logf == nil { logf = log.Printf diff --git a/net/tstun/wrap.go b/net/tstun/wrap.go index a43b0cb62..c11ecec08 100644 --- a/net/tstun/wrap.go +++ b/net/tstun/wrap.go @@ -60,7 +60,7 @@ var ( // parsedPacketPool holds a pool of Parsed structs for use in filtering. // This is needed because escape analysis cannot see that parsed packets // do not escape through {Pre,Post}Filter{In,Out}. -var parsedPacketPool = sync.Pool{New: func() interface{} { return new(packet.Parsed) }} +var parsedPacketPool = sync.Pool{New: func() any { return new(packet.Parsed) }} // FilterFunc is a packet-filtering function with access to the Wrapper device. // It must not hold onto the packet struct, as its backing storage will be reused. diff --git a/packages/deb/deb_test.go b/packages/deb/deb_test.go index d6f4c3806..e22b718d6 100644 --- a/packages/deb/deb_test.go +++ b/packages/deb/deb_test.go @@ -141,7 +141,7 @@ func TestDebInfo(t *testing.T) { } } -func diff(got, want interface{}) string { +func diff(got, want any) string { matchField := func(name string) func(p cmp.Path) bool { return func(p cmp.Path) bool { if len(p) != 3 { diff --git a/ssh/tailssh/context.go b/ssh/tailssh/context.go index 066eacf4a..b1e2bc12e 100644 --- a/ssh/tailssh/context.go +++ b/ssh/tailssh/context.go @@ -42,7 +42,7 @@ func (ctx *sshContext) Err() error { func (ctx *sshContext) Done() <-chan struct{} { return ctx.done } func (ctx *sshContext) Deadline() (deadline time.Time, ok bool) { return } -func (ctx *sshContext) Value(interface{}) interface{} { return nil } +func (ctx *sshContext) Value(any) any { return nil } // userVisibleError is a wrapper around an error that implements // SSHTerminationError, so msg is written to their session. diff --git a/ssh/tailssh/incubator_linux.go b/ssh/tailssh/incubator_linux.go index 5d6f448ed..245c3600a 100644 --- a/ssh/tailssh/incubator_linux.go +++ b/ssh/tailssh/incubator_linux.go @@ -35,7 +35,7 @@ func ptyNameLinux(f *os.File) (string, error) { // callLogin1 invokes the provided method of the "login1" service over D-Bus. // https://www.freedesktop.org/software/systemd/man/org.freedesktop.login1.html -func callLogin1(method string, flags dbus.Flags, args ...interface{}) (*dbus.Call, error) { +func callLogin1(method string, flags dbus.Flags, args ...any) (*dbus.Call, error) { conn, err := dbus.SystemBus() if err != nil { // DBus probably not running. @@ -77,8 +77,8 @@ type createSessionArgs struct { } } -func (a createSessionArgs) args() []interface{} { - return []interface{}{ +func (a createSessionArgs) args() []any { + return []any{ a.uid, a.pid, a.service, diff --git a/tailcfg/tailcfg_clone.go b/tailcfg/tailcfg_clone.go index d47fbed67..b1a3572ba 100644 --- a/tailcfg/tailcfg_clone.go +++ b/tailcfg/tailcfg_clone.go @@ -326,7 +326,7 @@ var _DERPNodeCloneNeedsRegeneration = DERPNode(struct { // Clone duplicates src into dst and reports whether it succeeded. // To succeed, must be of types <*T, *T> or <*T, **T>, // where T is one of User,Node,Hostinfo,NetInfo,Login,DNSConfig,RegisterResponse,DERPRegion,DERPMap,DERPNode. -func Clone(dst, src interface{}) bool { +func Clone(dst, src any) bool { switch src := src.(type) { case *User: switch dst := dst.(type) { diff --git a/tstest/integration/testcontrol/testcontrol.go b/tstest/integration/testcontrol/testcontrol.go index 7ef1ff894..ce6af5aa8 100644 --- a/tstest/integration/testcontrol/testcontrol.go +++ b/tstest/integration/testcontrol/testcontrol.go @@ -189,7 +189,7 @@ func (ap *AuthPath) CompleteSuccessfully() { ap.closeOnce.Do(ap.completeSuccessfully) } -func (s *Server) logf(format string, a ...interface{}) { +func (s *Server) logf(format string, a ...any) { if s.Logf != nil { s.Logf(format, a...) } else { @@ -779,7 +779,7 @@ func (s *Server) MapResponse(req *tailcfg.MapRequest) (res *tailcfg.MapResponse, return res, nil } -func (s *Server) sendMapMsg(w http.ResponseWriter, mkey key.MachinePublic, compress bool, msg interface{}) error { +func (s *Server) sendMapMsg(w http.ResponseWriter, mkey key.MachinePublic, compress bool, msg any) error { resBytes, err := s.encode(mkey, compress, msg) if err != nil { return err @@ -803,7 +803,7 @@ func (s *Server) sendMapMsg(w http.ResponseWriter, mkey key.MachinePublic, compr return nil } -func (s *Server) decode(mkey key.MachinePublic, msg []byte, v interface{}) error { +func (s *Server) decode(mkey key.MachinePublic, msg []byte, v any) error { if len(msg) == msgLimit { return errors.New("encrypted message too long") } @@ -816,7 +816,7 @@ func (s *Server) decode(mkey key.MachinePublic, msg []byte, v interface{}) error } var zstdEncoderPool = &sync.Pool{ - New: func() interface{} { + New: func() any { encoder, err := smallzstd.NewEncoder(nil, zstd.WithEncoderLevel(zstd.SpeedFastest)) if err != nil { panic(err) @@ -825,7 +825,7 @@ var zstdEncoderPool = &sync.Pool{ }, } -func (s *Server) encode(mkey key.MachinePublic, compress bool, v interface{}) (b []byte, err error) { +func (s *Server) encode(mkey key.MachinePublic, compress bool, v any) (b []byte, err error) { var isBytes bool if b, isBytes = v.([]byte); !isBytes { b, err = json.Marshal(v) diff --git a/tstest/log.go b/tstest/log.go index f27d32906..3f30dbdf9 100644 --- a/tstest/log.go +++ b/tstest/log.go @@ -82,7 +82,7 @@ type LogLineTracker struct { } // Logf logs to its underlying logger and also tracks that the given format pattern has been seen. -func (lt *LogLineTracker) Logf(format string, args ...interface{}) { +func (lt *LogLineTracker) Logf(format string, args ...any) { lt.mu.Lock() if lt.closed { lt.mu.Unlock() @@ -131,7 +131,7 @@ type MemLogger struct { bytes.Buffer } -func (ml *MemLogger) Logf(format string, args ...interface{}) { +func (ml *MemLogger) Logf(format string, args ...any) { ml.Lock() defer ml.Unlock() fmt.Fprintf(&ml.Buffer, format, args...) diff --git a/tstest/natlab/natlab.go b/tstest/natlab/natlab.go index d3cf76fc5..71479159c 100644 --- a/tstest/natlab/natlab.go +++ b/tstest/natlab/natlab.go @@ -66,16 +66,16 @@ func (p *Packet) short() string { return fmt.Sprintf("%s/%s", payload, tuple) } -func (p *Packet) Trace(msg string, args ...interface{}) { +func (p *Packet) Trace(msg string, args ...any) { if !traceOn { return } - allArgs := []interface{}{p.short(), p.locator, p.Src, p.Dst} + allArgs := []any{p.short(), p.locator, p.Src, p.Dst} allArgs = append(allArgs, args...) fmt.Fprintf(os.Stderr, "[%s]%s src=%s dst=%s "+msg+"\n", allArgs...) } -func (p *Packet) setLocator(msg string, args ...interface{}) { +func (p *Packet) setLocator(msg string, args ...any) { p.locator = fmt.Sprintf(" "+msg, args...) } diff --git a/tsweb/debug.go b/tsweb/debug.go index 54fd188cb..7a308e995 100644 --- a/tsweb/debug.go +++ b/tsweb/debug.go @@ -52,7 +52,7 @@ func Debugger(mux *http.ServeMux) *DebugHandler { // index page. The /pprof/ index already covers it. mux.Handle("/debug/pprof/profile", http.HandlerFunc(pprof.Profile)) - ret.KVFunc("Uptime", func() interface{} { return Uptime() }) + ret.KVFunc("Uptime", func() any { return Uptime() }) ret.KV("Version", version.Long) ret.Handle("vars", "Metrics (Go)", expvar.Handler()) ret.Handle("varz", "Metrics (Prometheus)", http.HandlerFunc(VarzHandler)) @@ -79,7 +79,7 @@ func (d *DebugHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { return } - f := func(format string, args ...interface{}) { fmt.Fprintf(w, format, args...) } + f := func(format string, args ...any) { fmt.Fprintf(w, format, args...) } f("

%s debug

    ", version.CmdName()) for _, kv := range d.kvs { kv(w) @@ -101,7 +101,7 @@ func (d *DebugHandler) Handle(slug, desc string, handler http.Handler) { } // KV adds a key/value list item to /debug/. -func (d *DebugHandler) KV(k string, v interface{}) { +func (d *DebugHandler) KV(k string, v any) { val := html.EscapeString(fmt.Sprintf("%v", v)) d.kvs = append(d.kvs, func(w io.Writer) { fmt.Fprintf(w, "
  • %s: %s
  • ", k, val) @@ -110,7 +110,7 @@ func (d *DebugHandler) KV(k string, v interface{}) { // KVFunc adds a key/value list item to /debug/. v is called on every // render of /debug/. -func (d *DebugHandler) KVFunc(k string, v func() interface{}) { +func (d *DebugHandler) KVFunc(k string, v func() any) { d.kvs = append(d.kvs, func(w io.Writer) { val := html.EscapeString(fmt.Sprintf("%v", v())) fmt.Fprintf(w, "
  • %s: %s
  • ", k, val) diff --git a/tsweb/debug_test.go b/tsweb/debug_test.go index 31f6aaa4f..f56a78812 100644 --- a/tsweb/debug_test.go +++ b/tsweb/debug_test.go @@ -66,7 +66,7 @@ func TestDebuggerKV(t *testing.T) { dbg.KV("Donuts", 42) dbg.KV("Secret code", "hunter2") val := "red" - dbg.KVFunc("Condition", func() interface{} { return val }) + dbg.KVFunc("Condition", func() any { return val }) code, _ := get(mux, "/debug/", pubIP) if code != 403 { @@ -183,7 +183,7 @@ func ExampleDebugHandler_KVFunc() { // Adds an count of page renders to /debug/. Note this example // isn't concurrency-safe. views := 0 - dbg.KVFunc("Debug pageviews", func() interface{} { + dbg.KVFunc("Debug pageviews", func() any { views = views + 1 return views }) diff --git a/tsweb/jsonhandler.go b/tsweb/jsonhandler.go index fb4c88136..da5182b22 100644 --- a/tsweb/jsonhandler.go +++ b/tsweb/jsonhandler.go @@ -19,16 +19,16 @@ import ( ) type response struct { - Status string `json:"status"` - Error string `json:"error,omitempty"` - Data interface{} `json:"data,omitempty"` + Status string `json:"status"` + Error string `json:"error,omitempty"` + Data any `json:"data,omitempty"` } // JSONHandlerFunc is an HTTP ReturnHandler that writes JSON responses to the client. // // Return a HTTPError to show an error message, otherwise JSONHandlerFunc will // only report "internal server error" to the user with status code 500. -type JSONHandlerFunc func(r *http.Request) (status int, data interface{}, err error) +type JSONHandlerFunc func(r *http.Request) (status int, data any, err error) // ServeHTTPReturn implements the ReturnHandler interface. // diff --git a/tsweb/jsonhandler_test.go b/tsweb/jsonhandler_test.go index 494c6494b..6514e7af6 100644 --- a/tsweb/jsonhandler_test.go +++ b/tsweb/jsonhandler_test.go @@ -71,7 +71,7 @@ func TestNewJSONHandler(t *testing.T) { return d } - h21 := JSONHandlerFunc(func(r *http.Request) (int, interface{}, error) { + h21 := JSONHandlerFunc(func(r *http.Request) (int, any, error) { return http.StatusOK, nil, nil }) @@ -83,7 +83,7 @@ func TestNewJSONHandler(t *testing.T) { }) t.Run("403 HTTPError", func(t *testing.T) { - h := JSONHandlerFunc(func(r *http.Request) (int, interface{}, error) { + h := JSONHandlerFunc(func(r *http.Request) (int, any, error) { return 0, nil, Error(http.StatusForbidden, "forbidden", nil) }) @@ -93,7 +93,7 @@ func TestNewJSONHandler(t *testing.T) { checkStatus(t, w, "error", http.StatusForbidden) }) - h22 := JSONHandlerFunc(func(r *http.Request) (int, interface{}, error) { + h22 := JSONHandlerFunc(func(r *http.Request) (int, any, error) { return http.StatusOK, &Data{Name: "tailscale"}, nil }) @@ -104,7 +104,7 @@ func TestNewJSONHandler(t *testing.T) { checkStatus(t, w, "success", http.StatusOK) }) - h31 := JSONHandlerFunc(func(r *http.Request) (int, interface{}, error) { + h31 := JSONHandlerFunc(func(r *http.Request) (int, any, error) { body := new(Data) if err := json.NewDecoder(r.Body).Decode(body); err != nil { return 0, nil, Error(http.StatusBadRequest, err.Error(), err) @@ -140,7 +140,7 @@ func TestNewJSONHandler(t *testing.T) { } }) - h32 := JSONHandlerFunc(func(r *http.Request) (int, interface{}, error) { + h32 := JSONHandlerFunc(func(r *http.Request) (int, any, error) { body := new(Data) if err := json.NewDecoder(r.Body).Decode(body); err != nil { return 0, nil, Error(http.StatusBadRequest, err.Error(), err) @@ -187,7 +187,7 @@ func TestNewJSONHandler(t *testing.T) { r := httptest.NewRequest("POST", "/", strings.NewReader(`{"Price": 10}`)) r.Header.Set("Accept-Encoding", "gzip") value := []string{"foo", "foo", "foo"} - JSONHandlerFunc(func(r *http.Request) (int, interface{}, error) { + JSONHandlerFunc(func(r *http.Request) (int, any, error) { return 400, value, nil }).ServeHTTPReturn(w, r) res := w.Result() @@ -222,7 +222,7 @@ func TestNewJSONHandler(t *testing.T) { t.Run("500 misuse", func(t *testing.T) { w := httptest.NewRecorder() r := httptest.NewRequest("POST", "/", nil) - JSONHandlerFunc(func(r *http.Request) (int, interface{}, error) { + JSONHandlerFunc(func(r *http.Request) (int, any, error) { return http.StatusOK, make(chan int), nil }).ServeHTTPReturn(w, r) resp := checkStatus(t, w, "error", http.StatusInternalServerError) @@ -234,7 +234,7 @@ func TestNewJSONHandler(t *testing.T) { t.Run("500 empty status code", func(t *testing.T) { w := httptest.NewRecorder() r := httptest.NewRequest("POST", "/", nil) - JSONHandlerFunc(func(r *http.Request) (status int, data interface{}, err error) { + JSONHandlerFunc(func(r *http.Request) (status int, data any, err error) { return }).ServeHTTPReturn(w, r) checkStatus(t, w, "error", http.StatusInternalServerError) @@ -243,7 +243,7 @@ func TestNewJSONHandler(t *testing.T) { t.Run("403 forbidden, status returned by JSONHandlerFunc and HTTPError agree", func(t *testing.T) { w := httptest.NewRecorder() r := httptest.NewRequest("POST", "/", nil) - JSONHandlerFunc(func(r *http.Request) (int, interface{}, error) { + JSONHandlerFunc(func(r *http.Request) (int, any, error) { return http.StatusForbidden, nil, Error(http.StatusForbidden, "403 forbidden", nil) }).ServeHTTPReturn(w, r) want := &Response{ @@ -260,7 +260,7 @@ func TestNewJSONHandler(t *testing.T) { t.Run("403 forbidden, status returned by JSONHandlerFunc and HTTPError do not agree", func(t *testing.T) { w := httptest.NewRecorder() r := httptest.NewRequest("POST", "/", nil) - err := JSONHandlerFunc(func(r *http.Request) (int, interface{}, error) { + err := JSONHandlerFunc(func(r *http.Request) (int, any, error) { return http.StatusInternalServerError, nil, Error(http.StatusForbidden, "403 forbidden", nil) }).ServeHTTPReturn(w, r) if !strings.HasPrefix(err.Error(), "[unexpected]") { diff --git a/tsweb/tsweb.go b/tsweb/tsweb.go index bd46cc90b..aa21c9eb0 100644 --- a/tsweb/tsweb.go +++ b/tsweb/tsweb.go @@ -33,10 +33,10 @@ import ( ) func init() { - expvar.Publish("process_start_unix_time", expvar.Func(func() interface{} { return timeStart.Unix() })) - expvar.Publish("version", expvar.Func(func() interface{} { return version.Long })) - expvar.Publish("counter_uptime_sec", expvar.Func(func() interface{} { return int64(Uptime().Seconds()) })) - expvar.Publish("gauge_goroutines", expvar.Func(func() interface{} { return runtime.NumGoroutine() })) + expvar.Publish("process_start_unix_time", expvar.Func(func() any { return timeStart.Unix() })) + expvar.Publish("version", expvar.Func(func() any { return version.Long })) + expvar.Publish("counter_uptime_sec", expvar.Func(func() any { return int64(Uptime().Seconds()) })) + expvar.Publish("gauge_goroutines", expvar.Func(func() any { return runtime.NumGoroutine() })) } // DevMode controls whether extra output in shown, for when the binary is being run in dev mode. @@ -513,7 +513,7 @@ type PrometheusMetricsReflectRooter interface { expvar.Var // PrometheusMetricsReflectRoot returns the struct or struct pointer to walk. - PrometheusMetricsReflectRoot() interface{} + PrometheusMetricsReflectRoot() any } var expvarDo = expvar.Do // pulled out for tests @@ -562,10 +562,10 @@ func foreachExportedStructField(rv reflect.Value, f func(fieldOrJSONName, metric } } -type expVarPromStructRoot struct{ v interface{} } +type expVarPromStructRoot struct{ v any } -func (r expVarPromStructRoot) PrometheusMetricsReflectRoot() interface{} { return r.v } -func (r expVarPromStructRoot) String() string { panic("unused") } +func (r expVarPromStructRoot) PrometheusMetricsReflectRoot() any { return r.v } +func (r expVarPromStructRoot) String() string { panic("unused") } var ( _ PrometheusMetricsReflectRooter = expVarPromStructRoot{} diff --git a/tsweb/tsweb_test.go b/tsweb/tsweb_test.go index 278725318..c7469f5da 100644 --- a/tsweb/tsweb_test.go +++ b/tsweb/tsweb_test.go @@ -241,7 +241,7 @@ func TestStdHandler(t *testing.T) { for _, test := range tests { t.Run(test.name, func(t *testing.T) { var logs []AccessLogRecord - logf := func(fmt string, args ...interface{}) { + logf := func(fmt string, args ...any) { if fmt == "%s" { logs = append(logs, args[0].(AccessLogRecord)) } @@ -378,19 +378,19 @@ func TestVarzHandler(t *testing.T) { { "func_float64", "counter_x", - expvar.Func(func() interface{} { return float64(1.2) }), + expvar.Func(func() any { return float64(1.2) }), "# TYPE x counter\nx 1.2\n", }, { "func_float64_gauge", "gauge_x", - expvar.Func(func() interface{} { return float64(1.2) }), + expvar.Func(func() any { return float64(1.2) }), "# TYPE x gauge\nx 1.2\n", }, { "func_float64_untyped", "x", - expvar.Func(func() interface{} { return float64(1.2) }), + expvar.Func(func() any { return float64(1.2) }), "x 1.2\n", }, { @@ -466,7 +466,7 @@ foo_AUint16 65535 { "func_returning_int", "num_goroutines", - expvar.Func(func() interface{} { return 123 }), + expvar.Func(func() any { return 123 }), "num_goroutines 123\n", }, } @@ -531,6 +531,6 @@ type expvarAdapter struct { func (expvarAdapter) String() string { return "{}" } // expvar JSON; unused in test -func (a expvarAdapter) PrometheusMetricsReflectRoot() interface{} { +func (a expvarAdapter) PrometheusMetricsReflectRoot() any { return a.st } diff --git a/types/dnstype/dnstype_clone.go b/types/dnstype/dnstype_clone.go index c155edb04..2954275fa 100644 --- a/types/dnstype/dnstype_clone.go +++ b/types/dnstype/dnstype_clone.go @@ -32,7 +32,7 @@ var _ResolverCloneNeedsRegeneration = Resolver(struct { // Clone duplicates src into dst and reports whether it succeeded. // To succeed, must be of types <*T, *T> or <*T, **T>, // where T is one of Resolver. -func Clone(dst, src interface{}) bool { +func Clone(dst, src any) bool { switch src := src.(type) { case *Resolver: switch dst := dst.(type) { diff --git a/types/logger/logger.go b/types/logger/logger.go index 28b2ef2d9..4e33f651a 100644 --- a/types/logger/logger.go +++ b/types/logger/logger.go @@ -28,7 +28,7 @@ import ( // Logf is the basic Tailscale logger type: a printf-like func. // Like log.Printf, the format need not end in a newline. // Logf functions must be safe for concurrent use. -type Logf func(format string, args ...interface{}) +type Logf func(format string, args ...any) // A Context is a context.Context that should contain a custom log function, obtainable from FromContext. // If no log function is present, FromContext will return log.Printf. @@ -43,7 +43,7 @@ type jenc struct { enc *json.Encoder } -var jencPool = &sync.Pool{New: func() interface{} { +var jencPool = &sync.Pool{New: func() any { je := new(jenc) je.enc = json.NewEncoder(&je.buf) return je @@ -61,7 +61,7 @@ var jencPool = &sync.Pool{New: func() interface{} { // // The level can be from 0 to 9. Levels from 1 to 9 are included in // the logged JSON object, like {"foo":123,"v":2}. -func (logf Logf) JSON(level int, recType string, v interface{}) { +func (logf Logf) JSON(level int, recType string, v any) { je := jencPool.Get().(*jenc) defer jencPool.Put(je) je.buf.Reset() @@ -96,7 +96,7 @@ func Ctx(ctx context.Context, fn Logf) Context { // WithPrefix wraps f, prefixing each format with the provided prefix. func WithPrefix(f Logf, prefix string) Logf { - return func(format string, args ...interface{}) { + return func(format string, args ...any) { f(prefix+format, args...) } } @@ -119,7 +119,7 @@ func (w funcWriter) Write(p []byte) (int, error) { } // Discard is a Logf that throws away the logs given to it. -func Discard(string, ...interface{}) {} +func Discard(string, ...any) {} // limitData is used to keep track of each format string's associated // rate-limiting data. @@ -165,7 +165,7 @@ func RateLimitedFnWithClock(logf Logf, f time.Duration, burst int, maxCache int, msgCache = list.New() // a rudimentary LRU that limits the size of the map ) - return func(format string, args ...interface{}) { + return func(format string, args ...any) { // Shortcut for formats with no rate limit for _, sub := range rateFree { if strings.Contains(format, sub) { @@ -239,7 +239,7 @@ func LogOnChange(logf Logf, maxInterval time.Duration, timeNow func() time.Time) tLastLogged = timeNow() ) - return func(format string, args ...interface{}) { + return func(format string, args ...any) { s := fmt.Sprintf(format, args...) mu.Lock() @@ -270,13 +270,13 @@ func (fn ArgWriter) Format(f fmt.State, _ rune) { argBufioPool.Put(bw) } -var argBufioPool = &sync.Pool{New: func() interface{} { return bufio.NewWriterSize(ioutil.Discard, 1024) }} +var argBufioPool = &sync.Pool{New: func() any { return bufio.NewWriterSize(ioutil.Discard, 1024) }} // Filtered returns a Logf that silently swallows some log lines. // Each inbound format and args is evaluated and printed to a string s. // The original format and args are passed to logf if and only if allow(s) returns true. func Filtered(logf Logf, allow func(s string) bool) Logf { - return func(format string, args ...interface{}) { + return func(format string, args ...any) { msg := fmt.Sprintf(format, args...) if !allow(msg) { return @@ -297,7 +297,7 @@ func LogfCloser(logf Logf) (newLogf Logf, close func()) { defer mu.Unlock() closed = true } - newLogf = func(msg string, args ...interface{}) { + newLogf = func(msg string, args ...any) { mu.Lock() if closed { mu.Unlock() diff --git a/types/logger/logger_test.go b/types/logger/logger_test.go index 77c869e89..43c96a31e 100644 --- a/types/logger/logger_test.go +++ b/types/logger/logger_test.go @@ -30,7 +30,7 @@ func TestStdLogger(t *testing.T) { } func logTester(want []string, t *testing.T, i *int) Logf { - return func(format string, args ...interface{}) { + return func(format string, args ...any) { got := fmt.Sprintf(format, args...) if *i >= len(want) { t.Fatalf("Logging continued past end of expected input: %s", got) @@ -204,7 +204,7 @@ func TestContext(t *testing.T) { // Test that FromContext and Ctx work together. var called bool - markCalled := func(string, ...interface{}) { + markCalled := func(string, ...any) { called = true } ctx = Ctx(ctx, markCalled) @@ -215,7 +215,7 @@ func TestContext(t *testing.T) { func TestJSON(t *testing.T) { var buf bytes.Buffer - var logf Logf = func(f string, a ...interface{}) { fmt.Fprintf(&buf, f, a...) } + var logf Logf = func(f string, a ...any) { fmt.Fprintf(&buf, f, a...) } logf.JSON(1, "foo", &tailcfg.Hostinfo{}) want := "[v\x00JSON]1" + `{"foo":{"OS":"","Hostname":""}}` if got := buf.String(); got != want { diff --git a/types/logger/rusage.go b/types/logger/rusage.go index feb6fd19c..daf2fdef4 100644 --- a/types/logger/rusage.go +++ b/types/logger/rusage.go @@ -13,7 +13,7 @@ import ( // a prefixed log message to each line with the current binary memory usage // and max RSS. func RusagePrefixLog(logf Logf) Logf { - return func(f string, argv ...interface{}) { + return func(f string, argv ...any) { var m runtime.MemStats runtime.ReadMemStats(&m) goMem := float64(m.HeapInuse+m.StackInuse) / (1 << 20) diff --git a/types/opt/bool.go b/types/opt/bool.go index 3b094a175..4ef991c0f 100644 --- a/types/opt/bool.go +++ b/types/opt/bool.go @@ -30,7 +30,7 @@ func (b Bool) Get() (v bool, ok bool) { } // Scan implements database/sql.Scanner. -func (b *Bool) Scan(src interface{}) error { +func (b *Bool) Scan(src any) error { if src == nil { *b = "" return nil diff --git a/types/opt/bool_test.go b/types/opt/bool_test.go index f7bfc910c..9b3424ee5 100644 --- a/types/opt/bool_test.go +++ b/types/opt/bool_test.go @@ -13,7 +13,7 @@ import ( func TestBool(t *testing.T) { tests := []struct { name string - in interface{} + in any want string // JSON }{ { diff --git a/util/clientmetric/clientmetric.go b/util/clientmetric/clientmetric.go index a78a648af..e31f26aa2 100644 --- a/util/clientmetric/clientmetric.go +++ b/util/clientmetric/clientmetric.go @@ -256,7 +256,7 @@ func EncodeLogTailMetricsDelta() string { } var deltaPool = &sync.Pool{ - New: func() interface{} { + New: func() any { return new(deltaEncBuf) }, } diff --git a/util/codegen/codegen.go b/util/codegen/codegen.go index 4265806ee..83f315d59 100644 --- a/util/codegen/codegen.go +++ b/util/codegen/codegen.go @@ -79,7 +79,7 @@ func NamedTypes(pkg *packages.Package) map[string]*types.Named { // for each package path that the caller must import for the returned code to compile. func AssertStructUnchanged(t *types.Struct, thisPkg *types.Package, tname, ctx string, imports map[string]struct{}) []byte { buf := new(bytes.Buffer) - w := func(format string, args ...interface{}) { + w := func(format string, args ...any) { fmt.Fprintf(buf, format+"\n", args...) } w("// A compilation failure here means this code must be regenerated, with the command at the top of this file.") diff --git a/util/deephash/deephash.go b/util/deephash/deephash.go index 719662869..23d910172 100644 --- a/util/deephash/deephash.go +++ b/util/deephash/deephash.go @@ -113,11 +113,11 @@ func (h *hasher) sum() (s Sum) { } var hasherPool = &sync.Pool{ - New: func() interface{} { return new(hasher) }, + New: func() any { return new(hasher) }, } // Hash returns the hash of v. -func Hash(v interface{}) (s Sum) { +func Hash(v any) (s Sum) { h := hasherPool.Get().(*hasher) defer hasherPool.Put(h) h.reset() @@ -130,7 +130,7 @@ func Hash(v interface{}) (s Sum) { } // Update sets last to the hash of v and reports whether its value changed. -func Update(last *Sum, v ...interface{}) (changed bool) { +func Update(last *Sum, v ...any) (changed bool) { sum := Hash(v) if sum == *last { // unchanged. @@ -304,7 +304,7 @@ type mapHasher struct { } var mapHasherPool = &sync.Pool{ - New: func() interface{} { return new(mapHasher) }, + New: func() any { return new(mapHasher) }, } type valueCache map[reflect.Type]reflect.Value diff --git a/util/deephash/deephash_test.go b/util/deephash/deephash_test.go index c42851fc9..ddbe3e94e 100644 --- a/util/deephash/deephash_test.go +++ b/util/deephash/deephash_test.go @@ -35,8 +35,8 @@ func (p appendBytes) AppendTo(b []byte) []byte { } func TestHash(t *testing.T) { - type tuple [2]interface{} - type iface struct{ X interface{} } + type tuple [2]any + type iface struct{ X any } type scalars struct { I8 int8 I16 int16 @@ -132,8 +132,8 @@ func TestDeepHash(t *testing.T) { } } -func getVal() []interface{} { - return []interface{}{ +func getVal() []any { + return []any{ &wgcfg.Config{ Name: "foo", Addresses: []netaddr.IPPrefix{netaddr.IPPrefixFrom(netaddr.IPFrom16([16]byte{3: 3}), 5)}, @@ -321,10 +321,10 @@ func TestExhaustive(t *testing.T) { // verify this doesn't loop forever, as it used to (Issue 2340) func TestMapCyclicFallback(t *testing.T) { type T struct { - M map[string]interface{} + M map[string]any } v := &T{ - M: map[string]interface{}{}, + M: map[string]any{}, } v.M["m"] = v.M Hash(v) diff --git a/util/jsonutil/unmarshal.go b/util/jsonutil/unmarshal.go index 2d344ef01..a403be542 100644 --- a/util/jsonutil/unmarshal.go +++ b/util/jsonutil/unmarshal.go @@ -20,13 +20,13 @@ type decoder struct { } var readerPool = sync.Pool{ - New: func() interface{} { + New: func() any { return bytes.NewReader(nil) }, } var decoderPool = sync.Pool{ - New: func() interface{} { + New: func() any { var d decoder d.r = readerPool.Get().(*bytes.Reader) d.dec = json.NewDecoder(d.r) @@ -47,7 +47,7 @@ var decoderPool = sync.Pool{ // don't use this Unmarshal. // // This Unmarshal allocates considerably less memory. -func Unmarshal(b []byte, v interface{}) error { +func Unmarshal(b []byte, v any) error { d := decoderPool.Get().(*decoder) d.r.Reset(b) off := d.dec.InputOffset() diff --git a/util/jsonutil/unmarshal_test.go b/util/jsonutil/unmarshal_test.go index 4b4a47578..04712422c 100644 --- a/util/jsonutil/unmarshal_test.go +++ b/util/jsonutil/unmarshal_test.go @@ -27,7 +27,7 @@ func TestCompareToStd(t *testing.T) { for _, test := range tests { b := []byte(test) - var ourV, stdV interface{} + var ourV, stdV any ourErr := Unmarshal(b, &ourV) stdErr := json.Unmarshal(b, &stdV) if (ourErr == nil) != (stdErr == nil) { @@ -47,7 +47,7 @@ func TestCompareToStd(t *testing.T) { } func BenchmarkUnmarshal(b *testing.B) { - var m interface{} + var m any j := []byte("5") b.ReportAllocs() for i := 0; i < b.N; i++ { @@ -56,7 +56,7 @@ func BenchmarkUnmarshal(b *testing.B) { } func BenchmarkStdUnmarshal(b *testing.B) { - var m interface{} + var m any j := []byte("5") b.ReportAllocs() for i := 0; i < b.N; i++ { diff --git a/util/multierr/multierr.go b/util/multierr/multierr.go index f4c8ecf93..6e17be3d4 100644 --- a/util/multierr/multierr.go +++ b/util/multierr/multierr.go @@ -78,7 +78,7 @@ func (e Error) Is(target error) bool { // As finds the first error in e that matches target, and if any is found, // sets target to that error value and returns true. Otherwise, it returns false. -func (e Error) As(target interface{}) bool { +func (e Error) As(target any) bool { for _, err := range e.errs { if ok := errors.As(err, target); ok { return true diff --git a/util/systemd/systemd_linux.go b/util/systemd/systemd_linux.go index 237f08434..1988e7257 100644 --- a/util/systemd/systemd_linux.go +++ b/util/systemd/systemd_linux.go @@ -25,7 +25,7 @@ type logOnce struct { sync.Once } -func (l *logOnce) logf(format string, args ...interface{}) { +func (l *logOnce) logf(format string, args ...any) { l.Once.Do(func() { log.Printf(format, args...) }) @@ -71,7 +71,7 @@ func Ready() { // CPU: 2min 38.469s // CGroup: /system.slice/tailscale.service // └─26741 /nix/store/sv6cj4mw2jajm9xkbwj07k29dj30lh0n-tailscale-date.20200727/bin/tailscaled --port 41641 -func Status(format string, args ...interface{}) { +func Status(format string, args ...any) { err := notifier().Notify(sdnotify.Statusf(format, args...)) if err != nil { statusOnce.logf("systemd: error notifying: %v", err) diff --git a/util/systemd/systemd_nonlinux.go b/util/systemd/systemd_nonlinux.go index 1a2411862..29f721fd6 100644 --- a/util/systemd/systemd_nonlinux.go +++ b/util/systemd/systemd_nonlinux.go @@ -7,5 +7,5 @@ package systemd -func Ready() {} -func Status(string, ...interface{}) {} +func Ready() {} +func Status(string, ...any) {} diff --git a/util/uniq/slice.go b/util/uniq/slice.go index 37898de44..fc1ff0d7a 100644 --- a/util/uniq/slice.go +++ b/util/uniq/slice.go @@ -23,7 +23,7 @@ func (e badTypeError) Error() string { // It adjusts the length of the slice appropriately and zeros the tail. // eq reports whether (*sliceptr)[i] and (*sliceptr)[j] are equal. // ModifySlice does O(len(*sliceptr)) operations. -func ModifySlice(sliceptr interface{}, eq func(i, j int) bool) { +func ModifySlice(sliceptr any, eq func(i, j int) bool) { rvp := reflect.ValueOf(sliceptr) if rvp.Type().Kind() != reflect.Ptr { panic(badTypeError{rvp.Type()}) diff --git a/wf/firewall.go b/wf/firewall.go index cc66290e5..100ac39fc 100644 --- a/wf/firewall.go +++ b/wf/firewall.go @@ -276,7 +276,7 @@ func (f *Firewall) permitNDP(w weight) error { fieldICMPType := wf.FieldIPLocalPort fieldICMPCode := wf.FieldIPRemotePort - var icmpConditions = func(t, c uint16, remoteAddress interface{}) []*wf.Match { + var icmpConditions = func(t, c uint16, remoteAddress any) []*wf.Match { conditions := []*wf.Match{ { Field: wf.FieldIPProtocol, @@ -359,7 +359,7 @@ func (f *Firewall) permitNDP(w weight) error { } func (f *Firewall) permitDHCPv6(w weight) error { - var dhcpConditions = func(remoteAddrs ...interface{}) []*wf.Match { + var dhcpConditions = func(remoteAddrs ...any) []*wf.Match { conditions := []*wf.Match{ { Field: wf.FieldIPProtocol, @@ -403,7 +403,7 @@ func (f *Firewall) permitDHCPv6(w weight) error { } func (f *Firewall) permitDHCPv4(w weight) error { - var dhcpConditions = func(remoteAddrs ...interface{}) []*wf.Match { + var dhcpConditions = func(remoteAddrs ...any) []*wf.Match { conditions := []*wf.Match{ { Field: wf.FieldIPProtocol, diff --git a/wgengine/filter/filter_test.go b/wgengine/filter/filter_test.go index a09927c0a..7f7e29116 100644 --- a/wgengine/filter/filter_test.go +++ b/wgengine/filter/filter_test.go @@ -432,7 +432,7 @@ func TestLoggingPrivacy(t *testing.T) { logged bool testLogger logger.Logf ) - logf := func(format string, args ...interface{}) { + logf := func(format string, args ...any) { testLogger(format, args...) logged = true } diff --git a/wgengine/magicsock/magicsock.go b/wgengine/magicsock/magicsock.go index 66e1f4e5b..b15148169 100644 --- a/wgengine/magicsock/magicsock.go +++ b/wgengine/magicsock/magicsock.go @@ -1197,7 +1197,7 @@ var errDropDerpPacket = errors.New("too many DERP packets queued; dropping") var errNoUDP = errors.New("no UDP available on platform") var udpAddrPool = &sync.Pool{ - New: func() interface{} { return new(net.UDPAddr) }, + New: func() any { return new(net.UDPAddr) }, } // sendUDP sends UDP packet b to ipp. diff --git a/wgengine/magicsock/magicsock_test.go b/wgengine/magicsock/magicsock_test.go index c62e58758..c0ffd07cf 100644 --- a/wgengine/magicsock/magicsock_test.go +++ b/wgengine/magicsock/magicsock_test.go @@ -543,7 +543,7 @@ func makeNestable(t *testing.T) (logf logger.Logf, setT func(t *testing.T)) { mu.Unlock() } - logf = func(s string, args ...interface{}) { + logf = func(s string, args ...any) { mu.RLock() t := cur @@ -922,7 +922,7 @@ func testActiveDiscovery(t *testing.T, d *devices) { setT(t) start := time.Now() - wlogf := func(msg string, args ...interface{}) { + wlogf := func(msg string, args ...any) { t.Helper() msg = fmt.Sprintf("%s: %s", time.Since(start).Truncate(time.Microsecond), msg) tlogf(msg, args...) diff --git a/wgengine/monitor/monitor.go b/wgengine/monitor/monitor.go index e566fc0cf..f5e3f64d6 100644 --- a/wgengine/monitor/monitor.go +++ b/wgengine/monitor/monitor.go @@ -340,7 +340,7 @@ func (m *Mon) debounce() { } } -func jsonSummary(x interface{}) interface{} { +func jsonSummary(x any) any { j, err := json.Marshal(x) if err != nil { return err diff --git a/wgengine/monitor/monitor_darwin.go b/wgengine/monitor/monitor_darwin.go index 1cd5d71e7..0dd4ef2ed 100644 --- a/wgengine/monitor/monitor_darwin.go +++ b/wgengine/monitor/monitor_darwin.go @@ -178,7 +178,7 @@ func ipOfAddr(a route.Addr) netaddr.IP { return netaddr.IP{} } -func fmtAddr(a route.Addr) interface{} { +func fmtAddr(a route.Addr) any { if a == nil { return nil } diff --git a/wgengine/netstack/netstack_test.go b/wgengine/netstack/netstack_test.go index 9cea5b842..c1a9594de 100644 --- a/wgengine/netstack/netstack_test.go +++ b/wgengine/netstack/netstack_test.go @@ -21,7 +21,7 @@ import ( func TestInjectInboundLeak(t *testing.T) { tunDev := tstun.NewFake() dialer := new(tsdial.Dialer) - logf := func(format string, args ...interface{}) { + logf := func(format string, args ...any) { if !t.Failed() { t.Logf(format, args...) } diff --git a/wgengine/router/router_linux.go b/wgengine/router/router_linux.go index 084775786..c206875c2 100644 --- a/wgengine/router/router_linux.go +++ b/wgengine/router/router_linux.go @@ -84,7 +84,7 @@ type netfilterRunner interface { type linuxRouter struct { closed syncs.AtomicBool - logf func(fmt string, args ...interface{}) + logf func(fmt string, args ...any) tunname string linkMon *monitor.Mon unregLinkMon func() diff --git a/wgengine/router/router_windows.go b/wgengine/router/router_windows.go index 37090f553..f9cf66269 100644 --- a/wgengine/router/router_windows.go +++ b/wgengine/router/router_windows.go @@ -28,7 +28,7 @@ import ( ) type winRouter struct { - logf func(fmt string, args ...interface{}) + logf func(fmt string, args ...any) linkMon *monitor.Mon // may be nil nativeTun *tun.NativeTun routeChangeCallback *winipcfg.RouteChangeCallback diff --git a/wgengine/watchdog.go b/wgengine/watchdog.go index 1353a1589..dc10624e6 100644 --- a/wgengine/watchdog.go +++ b/wgengine/watchdog.go @@ -44,8 +44,8 @@ func NewWatchdog(e Engine) Engine { type watchdogEngine struct { wrap Engine - logf func(format string, args ...interface{}) - fatalf func(format string, args ...interface{}) + logf func(format string, args ...any) + fatalf func(format string, args ...any) maxWait time.Duration } diff --git a/wgengine/watchdog_test.go b/wgengine/watchdog_test.go index 7297354cc..277767837 100644 --- a/wgengine/watchdog_test.go +++ b/wgengine/watchdog_test.go @@ -57,7 +57,7 @@ func TestWatchdog(t *testing.T) { logBuf := new(tstest.MemLogger) fatalCalled := make(chan struct{}) wdEngine.logf = logBuf.Logf - wdEngine.fatalf = func(format string, args ...interface{}) { + wdEngine.fatalf = func(format string, args ...any) { t.Logf("FATAL: %s", fmt.Sprintf(format, args...)) fatalCalled <- struct{}{} } diff --git a/wgengine/wgcfg/parser_test.go b/wgengine/wgcfg/parser_test.go index 3835172ed..a3331ec6e 100644 --- a/wgengine/wgcfg/parser_test.go +++ b/wgengine/wgcfg/parser_test.go @@ -25,7 +25,7 @@ func noError(t *testing.T, err error) bool { return false } -func equal(t *testing.T, expected, actual interface{}) bool { +func equal(t *testing.T, expected, actual any) bool { if reflect.DeepEqual(expected, actual) { return true } diff --git a/wgengine/wglog/wglog.go b/wgengine/wglog/wglog.go index eef14e46e..e78216e2b 100644 --- a/wgengine/wglog/wglog.go +++ b/wgengine/wglog/wglog.go @@ -37,7 +37,7 @@ type strCache struct { // and rewrites peer keys from wireguard-go into Tailscale format. func NewLogger(logf logger.Logf) *Logger { ret := new(Logger) - wrapper := func(format string, args ...interface{}) { + wrapper := func(format string, args ...any) { if strings.Contains(format, "Routine:") && !strings.Contains(format, "receive incoming") { // wireguard-go logs as it starts and stops routines. // Drop those; there are a lot of them, and they're just noise. @@ -60,7 +60,7 @@ func NewLogger(logf logger.Logf) *Logger { } // Duplicate the args slice so that we can modify it. // This is not always required, but the code required to avoid it is not worth the complexity. - newargs := make([]interface{}, len(args)) + newargs := make([]any, len(args)) copy(newargs, args) for i, arg := range newargs { // We want to replace *device.Peer args with the Tailscale-formatted version of themselves. diff --git a/wgengine/wglog/wglog_test.go b/wgengine/wglog/wglog_test.go index 937d86e2a..dc20e02f7 100644 --- a/wgengine/wglog/wglog_test.go +++ b/wgengine/wglog/wglog_test.go @@ -18,22 +18,22 @@ import ( func TestLogger(t *testing.T) { tests := []struct { format string - args []interface{} + args []any want string omit bool }{ {"hi", nil, "hi", false}, {"Routine: starting", nil, "", true}, - {"%v says it misses you", []interface{}{stringer("peer(IMTB…r7lM)")}, "[IMTBr] says it misses you", false}, + {"%v says it misses you", []any{stringer("peer(IMTB…r7lM)")}, "[IMTBr] says it misses you", false}, } type log struct { format string - args []interface{} + args []any } c := make(chan log, 1) - logf := func(format string, args ...interface{}) { + logf := func(format string, args ...any) { select { case c <- log{format, args}: default: