mirror of
https://github.com/tailscale/tailscale.git
synced 2025-01-05 14:57:49 +00:00
all: use any instead of interface{}
My favorite part of generics. Signed-off-by: Josh Bleecher Snyder <josh@tailscale.com>
This commit is contained in:
parent
5f176f24db
commit
0868329936
@ -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
|
||||
}
|
||||
|
@ -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, <src, dst> 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 {")
|
||||
|
@ -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()
|
||||
|
@ -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 == "-" {
|
||||
|
@ -35,7 +35,7 @@
|
||||
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 @@ func Run(args []string) (err error) {
|
||||
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
|
||||
|
@ -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),
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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()})
|
||||
|
@ -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")
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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 @@ func decode(res *http.Response, v interface{}, serverKey, serverNoiseKey key.Mac
|
||||
// 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
|
||||
|
@ -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)
|
||||
},
|
||||
}
|
||||
|
@ -802,7 +802,7 @@ func TestClientRecv(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
input []byte
|
||||
want interface{}
|
||||
want any
|
||||
}{
|
||||
{
|
||||
name: "ping",
|
||||
|
@ -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) {
|
||||
|
@ -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...)
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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()
|
||||
|
@ -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(`<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
@ -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()
|
||||
|
||||
|
@ -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")
|
||||
}
|
||||
|
@ -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)
|
||||
|
@ -42,7 +42,7 @@
|
||||
|
||||
// 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"
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
@ -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()
|
||||
|
||||
|
@ -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')
|
||||
}
|
||||
|
@ -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...)
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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]
|
||||
|
@ -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),
|
||||
})
|
||||
|
@ -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")
|
||||
}
|
||||
|
@ -711,7 +711,7 @@ type response struct {
|
||||
}
|
||||
|
||||
var dnsParserPool = &sync.Pool{
|
||||
New: func() interface{} {
|
||||
New: func() any {
|
||||
return new(dnsParser)
|
||||
},
|
||||
}
|
||||
|
@ -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")
|
||||
}
|
||||
|
@ -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(),
|
||||
|
||||
|
@ -129,7 +129,7 @@ type ipRes struct {
|
||||
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
|
||||
|
@ -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,
|
||||
|
@ -118,17 +118,17 @@ func mustParseResponse(t testing.TB, r []byte) (ret parsedMeta) {
|
||||
|
||||
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
|
||||
|
@ -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
|
||||
|
@ -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 {
|
||||
|
@ -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...)
|
||||
}
|
||||
|
@ -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)
|
||||
|
@ -15,7 +15,7 @@
|
||||
"inet.af/netaddr"
|
||||
)
|
||||
|
||||
type upnpClient interface{}
|
||||
type upnpClient any
|
||||
|
||||
type uPnPDiscoResponse struct{}
|
||||
|
||||
|
@ -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() {
|
||||
|
@ -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
|
||||
|
@ -60,7 +60,7 @@
|
||||
// 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.
|
||||
|
@ -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 {
|
||||
|
@ -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.
|
||||
|
@ -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,
|
||||
|
@ -326,7 +326,7 @@ func (src *DERPNode) Clone() *DERPNode {
|
||||
// Clone duplicates src into dst and reports whether it succeeded.
|
||||
// To succeed, <src, dst> 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) {
|
||||
|
@ -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 @@ func (s *Server) decode(mkey key.MachinePublic, msg []byte, v interface{}) error
|
||||
},
|
||||
}
|
||||
|
||||
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)
|
||||
|
@ -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...)
|
||||
|
@ -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...)
|
||||
}
|
||||
|
||||
|
@ -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("<html><body><h1>%s debug</h1><ul>", 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, "<li><b>%s:</b> %s</li>", 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, "<li><b>%s:</b> %s</li>", k, val)
|
||||
|
@ -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
|
||||
})
|
||||
|
@ -19,16 +19,16 @@
|
||||
)
|
||||
|
||||
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.
|
||||
//
|
||||
|
@ -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]") {
|
||||
|
@ -33,10 +33,10 @@
|
||||
)
|
||||
|
||||
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{}
|
||||
|
@ -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() *expvar.Map {
|
||||
{
|
||||
"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 @@ func() *expvar.Map {
|
||||
{
|
||||
"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
|
||||
}
|
||||
|
@ -32,7 +32,7 @@ func (src *Resolver) Clone() *Resolver {
|
||||
// Clone duplicates src into dst and reports whether it succeeded.
|
||||
// To succeed, <src, dst> 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) {
|
||||
|
@ -28,7 +28,7 @@
|
||||
// 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 @@ type jenc struct {
|
||||
//
|
||||
// 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()
|
||||
|
@ -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 {
|
||||
|
@ -13,7 +13,7 @@
|
||||
// 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)
|
||||
|
@ -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
|
||||
|
@ -13,7 +13,7 @@
|
||||
func TestBool(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
in interface{}
|
||||
in any
|
||||
want string // JSON
|
||||
}{
|
||||
{
|
||||
|
@ -256,7 +256,7 @@ func EncodeLogTailMetricsDelta() string {
|
||||
}
|
||||
|
||||
var deltaPool = &sync.Pool{
|
||||
New: func() interface{} {
|
||||
New: func() any {
|
||||
return new(deltaEncBuf)
|
||||
},
|
||||
}
|
||||
|
@ -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.")
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
@ -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 @@ type decoder struct {
|
||||
// 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()
|
||||
|
@ -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++ {
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
@ -7,5 +7,5 @@
|
||||
|
||||
package systemd
|
||||
|
||||
func Ready() {}
|
||||
func Status(string, ...interface{}) {}
|
||||
func Ready() {}
|
||||
func Status(string, ...any) {}
|
||||
|
@ -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()})
|
||||
|
@ -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,
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -1197,7 +1197,7 @@ func (c *Conn) Send(b []byte, ep conn.Endpoint) error {
|
||||
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.
|
||||
|
@ -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...)
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -21,7 +21,7 @@
|
||||
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...)
|
||||
}
|
||||
|
@ -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()
|
||||
|
@ -28,7 +28,7 @@
|
||||
)
|
||||
|
||||
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
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -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{}{}
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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.
|
||||
|
@ -18,22 +18,22 @@
|
||||
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:
|
||||
|
Loading…
x
Reference in New Issue
Block a user