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