mirror of
https://github.com/tailscale/tailscale.git
synced 2025-07-30 07:43:42 +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,
|
// Reply codes starting with 0 stand for ‘action successfully completed’ messages,
|
||||||
// 1 means ‘table entry’, 8 ‘runtime error’ and 9 ‘syntax error’.
|
// 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 {
|
if _, err := fmt.Fprintf(b.conn, cmd, args...); err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
@ -69,14 +69,14 @@ func main() {
|
|||||||
gen(buf, imports, typ, pkg.Types)
|
gen(buf, imports, typ, pkg.Types)
|
||||||
}
|
}
|
||||||
|
|
||||||
w := func(format string, args ...interface{}) {
|
w := func(format string, args ...any) {
|
||||||
fmt.Fprintf(buf, format+"\n", args...)
|
fmt.Fprintf(buf, format+"\n", args...)
|
||||||
}
|
}
|
||||||
if *flagCloneFunc {
|
if *flagCloneFunc {
|
||||||
w("// Clone duplicates src into dst and reports whether it succeeded.")
|
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("// To succeed, <src, dst> must be of types <*T, *T> or <*T, **T>,")
|
||||||
w("// where T is one of %s.", *flagTypes)
|
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) {")
|
w(" switch src := src.(type) {")
|
||||||
for _, typeName := range typeNames {
|
for _, typeName := range typeNames {
|
||||||
w(" case *%s:", typeName)
|
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, "// Clone makes a deep copy of %s.\n", name)
|
||||||
fmt.Fprintf(buf, "// The result aliases no memory with the original.\n")
|
fmt.Fprintf(buf, "// The result aliases no memory with the original.\n")
|
||||||
fmt.Fprintf(buf, "func (src *%s) Clone() *%s {\n", name, name)
|
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...)
|
fmt.Fprintf(buf, "\t"+format+"\n", args...)
|
||||||
}
|
}
|
||||||
writef("if src == nil {")
|
writef("if src == nil {")
|
||||||
|
@ -78,11 +78,11 @@ type overallStatus struct {
|
|||||||
good, bad []string
|
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...))
|
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...))
|
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.
|
// 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() {
|
go func() {
|
||||||
for {
|
for {
|
||||||
m, err := toc.Recv()
|
m, err := toc.Recv()
|
||||||
|
@ -79,7 +79,7 @@ func runCert(ctx context.Context, args []string) error {
|
|||||||
}
|
}
|
||||||
domain := args[0]
|
domain := args[0]
|
||||||
|
|
||||||
printf := func(format string, a ...interface{}) {
|
printf := func(format string, a ...any) {
|
||||||
printf(format, a...)
|
printf(format, a...)
|
||||||
}
|
}
|
||||||
if certArgs.certFile == "-" || certArgs.keyFile == "-" {
|
if certArgs.certFile == "-" || certArgs.keyFile == "-" {
|
||||||
|
@ -35,7 +35,7 @@ import (
|
|||||||
var Stderr io.Writer = os.Stderr
|
var Stderr io.Writer = os.Stderr
|
||||||
var Stdout io.Writer = os.Stdout
|
var Stdout io.Writer = os.Stdout
|
||||||
|
|
||||||
func printf(format string, a ...interface{}) {
|
func printf(format string, a ...any) {
|
||||||
fmt.Fprintf(Stdout, format, a...)
|
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
|
// It's not named println because that looks like the Go built-in
|
||||||
// which goes to stderr and formats slightly differently.
|
// which goes to stderr and formats slightly differently.
|
||||||
func outln(a ...interface{}) {
|
func outln(a ...any) {
|
||||||
fmt.Fprintln(Stdout, a...)
|
fmt.Fprintln(Stdout, a...)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -216,7 +216,7 @@ change in the future.
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func fatalf(format string, a ...interface{}) {
|
func fatalf(format string, a ...any) {
|
||||||
if Fatalf != nil {
|
if Fatalf != nil {
|
||||||
Fatalf(format, a...)
|
Fatalf(format, a...)
|
||||||
return
|
return
|
||||||
@ -226,7 +226,7 @@ func fatalf(format string, a ...interface{}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Fatalf, if non-nil, is used instead of log.Fatalf.
|
// 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 {
|
var rootArgs struct {
|
||||||
socket string
|
socket string
|
||||||
|
@ -136,7 +136,7 @@ func runStatus(ctx context.Context, args []string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var buf bytes.Buffer
|
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) {
|
printPS := func(ps *ipnstate.PeerStatus) {
|
||||||
f("%-15s %-20s %-12s %-7s ",
|
f("%-15s %-20s %-12s %-7s ",
|
||||||
firstIPString(ps.TailscaleIPs),
|
firstIPString(ps.TailscaleIPs),
|
||||||
|
@ -192,7 +192,7 @@ type upOutputJSON struct {
|
|||||||
Error string `json:",omitempty"` // description of an error
|
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...)
|
printf("Warning: "+format+"\n", args...)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -823,8 +823,8 @@ func flagAppliesToOS(flag, goos string) bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func prefsToFlags(env upCheckEnv, prefs *ipn.Prefs) (flagVal map[string]interface{}) {
|
func prefsToFlags(env upCheckEnv, prefs *ipn.Prefs) (flagVal map[string]any) {
|
||||||
ret := make(map[string]interface{})
|
ret := make(map[string]any)
|
||||||
|
|
||||||
exitNodeIPStr := func() string {
|
exitNodeIPStr := func() string {
|
||||||
if !prefs.ExitNodeIP.IsZero() {
|
if !prefs.ExitNodeIP.IsZero() {
|
||||||
@ -841,7 +841,7 @@ func prefsToFlags(env upCheckEnv, prefs *ipn.Prefs) (flagVal map[string]interfac
|
|||||||
if preflessFlag(f.Name) {
|
if preflessFlag(f.Name) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
set := func(v interface{}) {
|
set := func(v any) {
|
||||||
if flagAppliesToOS(f.Name, env.goos) {
|
if flagAppliesToOS(f.Name, env.goos) {
|
||||||
ret[f.Name] = v
|
ret[f.Name] = v
|
||||||
} else {
|
} else {
|
||||||
@ -895,7 +895,7 @@ func prefsToFlags(env upCheckEnv, prefs *ipn.Prefs) (flagVal map[string]interfac
|
|||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
func fmtFlagValueArg(flagName string, val interface{}) string {
|
func fmtFlagValueArg(flagName string, val any) string {
|
||||||
if val == true {
|
if val == true {
|
||||||
return "--" + flagName
|
return "--" + flagName
|
||||||
}
|
}
|
||||||
|
@ -313,7 +313,7 @@ func webHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
AdvertiseExitNode bool
|
AdvertiseExitNode bool
|
||||||
Reauthenticate bool
|
Reauthenticate bool
|
||||||
}
|
}
|
||||||
type mi map[string]interface{}
|
type mi map[string]any
|
||||||
if err := json.NewDecoder(r.Body).Decode(&postData); err != nil {
|
if err := json.NewDecoder(r.Body).Decode(&postData); err != nil {
|
||||||
w.WriteHeader(400)
|
w.WriteHeader(400)
|
||||||
json.NewEncoder(w).Encode(mi{"error": err.Error()})
|
json.NewEncoder(w).Encode(mi{"error": err.Error()})
|
||||||
|
@ -46,10 +46,10 @@ type fakeTB struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (t fakeTB) Cleanup(_ func()) {}
|
func (t fakeTB) Cleanup(_ func()) {}
|
||||||
func (t fakeTB) Error(args ...interface{}) {
|
func (t fakeTB) Error(args ...any) {
|
||||||
t.Fatal(args...)
|
t.Fatal(args...)
|
||||||
}
|
}
|
||||||
func (t fakeTB) Errorf(format string, args ...interface{}) {
|
func (t fakeTB) Errorf(format string, args ...any) {
|
||||||
t.Fatalf(format, args...)
|
t.Fatalf(format, args...)
|
||||||
}
|
}
|
||||||
func (t fakeTB) Fail() {
|
func (t fakeTB) Fail() {
|
||||||
@ -61,17 +61,17 @@ func (t fakeTB) FailNow() {
|
|||||||
func (t fakeTB) Failed() bool {
|
func (t fakeTB) Failed() bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
func (t fakeTB) Fatal(args ...interface{}) {
|
func (t fakeTB) Fatal(args ...any) {
|
||||||
log.Fatal(args...)
|
log.Fatal(args...)
|
||||||
}
|
}
|
||||||
func (t fakeTB) Fatalf(format string, args ...interface{}) {
|
func (t fakeTB) Fatalf(format string, args ...any) {
|
||||||
log.Fatalf(format, args...)
|
log.Fatalf(format, args...)
|
||||||
}
|
}
|
||||||
func (t fakeTB) Helper() {}
|
func (t fakeTB) Helper() {}
|
||||||
func (t fakeTB) Log(args ...interface{}) {
|
func (t fakeTB) Log(args ...any) {
|
||||||
log.Print(args...)
|
log.Print(args...)
|
||||||
}
|
}
|
||||||
func (t fakeTB) Logf(format string, args ...interface{}) {
|
func (t fakeTB) Logf(format string, args ...any) {
|
||||||
log.Printf(format, args...)
|
log.Printf(format, args...)
|
||||||
}
|
}
|
||||||
func (t fakeTB) Name() string {
|
func (t fakeTB) Name() string {
|
||||||
@ -80,13 +80,13 @@ func (t fakeTB) Name() string {
|
|||||||
func (t fakeTB) Setenv(key string, value string) {
|
func (t fakeTB) Setenv(key string, value string) {
|
||||||
panic("not implemented")
|
panic("not implemented")
|
||||||
}
|
}
|
||||||
func (t fakeTB) Skip(args ...interface{}) {
|
func (t fakeTB) Skip(args ...any) {
|
||||||
t.Fatal("skipped")
|
t.Fatal("skipped")
|
||||||
}
|
}
|
||||||
func (t fakeTB) SkipNow() {
|
func (t fakeTB) SkipNow() {
|
||||||
t.Fatal("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.Logf(format, args...)
|
||||||
t.Fatal("skipped")
|
t.Fatal("skipped")
|
||||||
}
|
}
|
||||||
|
@ -92,7 +92,7 @@ func NewNoStart(opts Options) (*Auto, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if opts.Logf == nil {
|
if opts.Logf == nil {
|
||||||
opts.Logf = func(fmt string, args ...interface{}) {}
|
opts.Logf = func(fmt string, args ...any) {}
|
||||||
}
|
}
|
||||||
if opts.TimeNow == nil {
|
if opts.TimeNow == nil {
|
||||||
opts.TimeNow = time.Now
|
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,
|
// 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.
|
// 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()
|
defer res.Body.Close()
|
||||||
msg, err := ioutil.ReadAll(io.LimitReader(res.Body, 1<<20))
|
msg, err := ioutil.ReadAll(io.LimitReader(res.Body, 1<<20))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -970,7 +970,7 @@ var jsonEscapedZero = []byte(`\u0000`)
|
|||||||
// decodeMsg is responsible for uncompressing msg and unmarshaling into v.
|
// decodeMsg is responsible for uncompressing msg and unmarshaling into v.
|
||||||
// If c.serverNoiseKey is not specified, it uses the c.serverKey and mkey
|
// If c.serverNoiseKey is not specified, it uses the c.serverKey and mkey
|
||||||
// to first the decrypt msg from the NaCl-crypto-box.
|
// 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()
|
c.mu.Lock()
|
||||||
serverKey := c.serverKey
|
serverKey := c.serverKey
|
||||||
serverNoiseKey := c.serverNoiseKey
|
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)
|
decrypted, ok := machinePrivKey.OpenFrom(serverKey, msg)
|
||||||
if !ok {
|
if !ok {
|
||||||
return errors.New("cannot decrypt response")
|
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
|
// encode JSON encodes v. If serverNoiseKey is not specified, it uses the serverKey and mkey to
|
||||||
// seal the message into a NaCl-crypto-box.
|
// 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)
|
b, err := json.Marshal(v)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -1310,7 +1310,7 @@ func (c *Direct) getNoiseClient() (*noiseClient, error) {
|
|||||||
if nc != nil {
|
if nc != nil {
|
||||||
return 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()
|
k, err := c.getMachinePrivKey()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -1641,8 +1641,8 @@ func (m multiForwarder) ForwardPacket(src, dst key.NodePublic, payload []byte) e
|
|||||||
return fwd.ForwardPacket(src, dst, payload)
|
return fwd.ForwardPacket(src, dst, payload)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) expVarFunc(f func() interface{}) expvar.Func {
|
func (s *Server) expVarFunc(f func() any) expvar.Func {
|
||||||
return expvar.Func(func() interface{} {
|
return expvar.Func(func() any {
|
||||||
s.mu.Lock()
|
s.mu.Lock()
|
||||||
defer s.mu.Unlock()
|
defer s.mu.Unlock()
|
||||||
return f()
|
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.
|
// ExpVar returns an expvar variable suitable for registering with expvar.Publish.
|
||||||
func (s *Server) ExpVar() expvar.Var {
|
func (s *Server) ExpVar() expvar.Var {
|
||||||
m := new(metrics.Set)
|
m := new(metrics.Set)
|
||||||
m.Set("gauge_memstats_sys0", expvar.Func(func() interface{} { return int64(s.memSys0) }))
|
m.Set("gauge_memstats_sys0", expvar.Func(func() any { return int64(s.memSys0) }))
|
||||||
m.Set("gauge_watchers", s.expVarFunc(func() interface{} { return len(s.watchers) }))
|
m.Set("gauge_watchers", s.expVarFunc(func() any { return len(s.watchers) }))
|
||||||
m.Set("gauge_current_file_descriptors", expvar.Func(func() interface{} { return metrics.CurrentFDs() }))
|
m.Set("gauge_current_file_descriptors", expvar.Func(func() any { return metrics.CurrentFDs() }))
|
||||||
m.Set("gauge_current_connections", &s.curClients)
|
m.Set("gauge_current_connections", &s.curClients)
|
||||||
m.Set("gauge_current_home_connections", &s.curHomeClients)
|
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_total", expvar.Func(func() any { return len(s.clientsMesh) }))
|
||||||
m.Set("gauge_clients_local", expvar.Func(func() interface{} { return len(s.clients) }))
|
m.Set("gauge_clients_local", expvar.Func(func() any { return len(s.clients) }))
|
||||||
m.Set("gauge_clients_remote", expvar.Func(func() interface{} { return len(s.clientsMesh) - 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_keys", &s.dupClientKeys)
|
||||||
m.Set("gauge_current_dup_client_conns", &s.dupClientConns)
|
m.Set("gauge_current_dup_client_conns", &s.dupClientConns)
|
||||||
m.Set("counter_total_dup_client_conns", &s.dupClientConnTotal)
|
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_created", &s.multiForwarderCreated)
|
||||||
m.Set("multiforwarder_deleted", &s.multiForwarderDeleted)
|
m.Set("multiforwarder_deleted", &s.multiForwarderDeleted)
|
||||||
m.Set("packet_forwarder_delete_other_value", &s.removePktForwardOther)
|
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))
|
return math.Float64frombits(atomic.LoadUint64(s.avgQueueDuration))
|
||||||
}))
|
}))
|
||||||
var expvarVersion expvar.String
|
var expvarVersion expvar.String
|
||||||
@ -1813,7 +1813,7 @@ func (s *Server) ServeDebugTraffic(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var bufioWriterPool = &sync.Pool{
|
var bufioWriterPool = &sync.Pool{
|
||||||
New: func() interface{} {
|
New: func() any {
|
||||||
return bufio.NewWriterSize(ioutil.Discard, 2<<10)
|
return bufio.NewWriterSize(ioutil.Discard, 2<<10)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -802,7 +802,7 @@ func TestClientRecv(t *testing.T) {
|
|||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
input []byte
|
input []byte
|
||||||
want interface{}
|
want any
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "ping",
|
name: "ping",
|
||||||
|
@ -46,7 +46,7 @@ func noteEnv(k, v string) {
|
|||||||
// logf is logger.Logf, but logger depends on envknob, so for circular
|
// logf is logger.Logf, but logger depends on envknob, so for circular
|
||||||
// dependency reasons, make a type alias (so it's still assignable,
|
// dependency reasons, make a type alias (so it's still assignable,
|
||||||
// but has nice docs here).
|
// 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.
|
// LogCurrent logs the currently set environment knobs.
|
||||||
func LogCurrent(logf logf) {
|
func LogCurrent(logf logf) {
|
||||||
|
@ -519,7 +519,7 @@ type peerAPIHandler struct {
|
|||||||
peerUser tailcfg.UserProfile // profile of peerNode
|
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...)
|
h.ps.b.logf("peerapi: "+format, a...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -83,7 +83,7 @@ func (b *LocalBackend) hostKeyFileOrCreate(keyDir, typ string) ([]byte, error) {
|
|||||||
if !os.IsNotExist(err) {
|
if !os.IsNotExist(err) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
var priv interface{}
|
var priv any
|
||||||
switch typ {
|
switch typ {
|
||||||
default:
|
default:
|
||||||
return nil, fmt.Errorf("unsupported key type %q", typ)
|
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 {
|
if cc.preventLog.Get() || cc.logfActual == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -28,7 +28,7 @@ func TestRunMultipleAccepts(t *testing.T) {
|
|||||||
td := t.TempDir()
|
td := t.TempDir()
|
||||||
socketPath := filepath.Join(td, "tailscale.sock")
|
socketPath := filepath.Join(td, "tailscale.sock")
|
||||||
|
|
||||||
logf := func(format string, args ...interface{}) {
|
logf := func(format string, args ...any) {
|
||||||
format = strings.TrimRight(format, "\n")
|
format = strings.TrimRight(format, "\n")
|
||||||
println(fmt.Sprintf(format, args...))
|
println(fmt.Sprintf(format, args...))
|
||||||
t.Logf(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...)
|
logf(format, args...)
|
||||||
if strings.HasPrefix(format, "Listening on ") {
|
if strings.HasPrefix(format, "Listening on ") {
|
||||||
connect()
|
connect()
|
||||||
|
@ -342,7 +342,7 @@ type StatusUpdater interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (st *Status) WriteHTML(w io.Writer) {
|
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>
|
f(`<!DOCTYPE html>
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
|
@ -85,7 +85,7 @@ func (h *Handler) serveCert(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
logf := logger.WithPrefix(h.logf, fmt.Sprintf("cert(%q): ", domain))
|
logf := logger.WithPrefix(h.logf, fmt.Sprintf("cert(%q): ", domain))
|
||||||
traceACME := func(v interface{}) {
|
traceACME := func(v any) {
|
||||||
if !acmeDebug {
|
if !acmeDebug {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -164,7 +164,7 @@ func (h *Handler) getCertPEMCached(dir, domain string, now time.Time) (p *keyPai
|
|||||||
return nil, false
|
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()
|
acmeMu.Lock()
|
||||||
defer acmeMu.Unlock()
|
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
|
// (currently only a slice or a map) and makes sure it's non-nil for
|
||||||
// JSON serialization. (In particular, JavaScript clients usually want
|
// JSON serialization. (In particular, JavaScript clients usually want
|
||||||
// the field to be defined after they decode the JSON.)
|
// the field to be defined after they decode the JSON.)
|
||||||
func makeNonNil(ptr interface{}) {
|
func makeNonNil(ptr any) {
|
||||||
if ptr == nil {
|
if ptr == nil {
|
||||||
panic("nil interface")
|
panic("nil interface")
|
||||||
}
|
}
|
||||||
|
@ -85,10 +85,10 @@ func TestClientServer(t *testing.T) {
|
|||||||
clientToServer := func(b []byte) {
|
clientToServer := func(b []byte) {
|
||||||
bs.GotCommandMsg(context.TODO(), b)
|
bs.GotCommandMsg(context.TODO(), b)
|
||||||
}
|
}
|
||||||
slogf := func(fmt string, args ...interface{}) {
|
slogf := func(fmt string, args ...any) {
|
||||||
t.Logf("s: "+fmt, args...)
|
t.Logf("s: "+fmt, args...)
|
||||||
}
|
}
|
||||||
clogf := func(fmt string, args ...interface{}) {
|
clogf := func(fmt string, args ...any) {
|
||||||
t.Logf("c: "+fmt, args...)
|
t.Logf("c: "+fmt, args...)
|
||||||
}
|
}
|
||||||
bs = NewBackendServer(slogf, b, serverToClient)
|
bs = NewBackendServer(slogf, b, serverToClient)
|
||||||
|
@ -42,7 +42,7 @@ var (
|
|||||||
|
|
||||||
// IsLoginServerSynonym reports whether a URL is a drop-in replacement
|
// IsLoginServerSynonym reports whether a URL is a drop-in replacement
|
||||||
// for the primary Tailscale login server.
|
// 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"
|
return val == "https://login.tailscale.com" || val == "https://controlplane.tailscale.com"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -110,7 +110,7 @@ func getError(resp *http.Response) error {
|
|||||||
return st
|
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()
|
tk, err := c.getOrRenewToken()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -77,7 +77,7 @@ func dayOf(t time.Time) civilDay {
|
|||||||
return civilDay{t.Year(), t.Month(), t.Day()}
|
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()
|
w.mu.Lock()
|
||||||
defer w.mu.Unlock()
|
defer w.mu.Unlock()
|
||||||
|
|
||||||
|
@ -416,7 +416,7 @@ func New(collection string) *Policy {
|
|||||||
console := log.New(stderrWriter{}, "", lflags)
|
console := log.New(stderrWriter{}, "", lflags)
|
||||||
|
|
||||||
var earlyErrBuf bytes.Buffer
|
var earlyErrBuf bytes.Buffer
|
||||||
earlyLogf := func(format string, a ...interface{}) {
|
earlyLogf := func(format string, a ...any) {
|
||||||
fmt.Fprintf(&earlyErrBuf, format, a...)
|
fmt.Fprintf(&earlyErrBuf, format, a...)
|
||||||
earlyErrBuf.WriteByte('\n')
|
earlyErrBuf.WriteByte('\n')
|
||||||
}
|
}
|
||||||
|
@ -515,7 +515,7 @@ func (l *Logger) encode(buf []byte, level int) []byte {
|
|||||||
|
|
||||||
now := l.timeNow()
|
now := l.timeNow()
|
||||||
|
|
||||||
obj := make(map[string]interface{})
|
obj := make(map[string]any)
|
||||||
if err := json.Unmarshal(buf, &obj); err != nil {
|
if err := json.Unmarshal(buf, &obj); err != nil {
|
||||||
for k := range obj {
|
for k := range obj {
|
||||||
delete(obj, k)
|
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.
|
// 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...)
|
fmt.Fprintf(l, format, args...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -128,7 +128,7 @@ func TestEncodeAndUploadMessages(t *testing.T) {
|
|||||||
|
|
||||||
ltail, ok := data["logtail"]
|
ltail, ok := data["logtail"]
|
||||||
if ok {
|
if ok {
|
||||||
logtailmap := ltail.(map[string]interface{})
|
logtailmap := ltail.(map[string]any)
|
||||||
_, ok = logtailmap["client_time"]
|
_, ok = logtailmap["client_time"]
|
||||||
if !ok {
|
if !ok {
|
||||||
t.Errorf("%s: no client_time present", tt.name)
|
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()
|
t.Helper()
|
||||||
var entries []map[string]interface{}
|
var entries []map[string]any
|
||||||
err := json.Unmarshal(body, &entries)
|
err := json.Unmarshal(body, &entries)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
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) {
|
func (m memFS) Stat(name string) (isRegular bool, err error) {
|
||||||
v, ok := m[name]
|
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
|
// NetworkManager wipes out IPv6 address configuration unless we
|
||||||
// tell it explicitly to keep it. Read out the current interface
|
// tell it explicitly to keep it. Read out the current interface
|
||||||
// settings and mirror them out to NetworkManager.
|
// settings and mirror them out to NetworkManager.
|
||||||
var addrs6 []map[string]interface{}
|
var addrs6 []map[string]any
|
||||||
addrs, _, err := interfaces.Tailscale()
|
addrs, _, err := interfaces.Tailscale()
|
||||||
if err == nil {
|
if err == nil {
|
||||||
for _, a := range addrs {
|
for _, a := range addrs {
|
||||||
if a.Is6() {
|
if a.Is6() {
|
||||||
addrs6 = append(addrs6, map[string]interface{}{
|
addrs6 = append(addrs6, map[string]any{
|
||||||
"address": a.String(),
|
"address": a.String(),
|
||||||
"prefix": uint32(128),
|
"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 {
|
if signal.Path != dbusPath || signal.Name != dbusInterface+"."+dbusOwnerSignal {
|
||||||
continue
|
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 {
|
if len(signal.Body) != 3 {
|
||||||
m.logf("[unexpectected] DBus NameOwnerChanged len(Body) = %d, want 3")
|
m.logf("[unexpectected] DBus NameOwnerChanged len(Body) = %d, want 3")
|
||||||
}
|
}
|
||||||
|
@ -711,7 +711,7 @@ type response struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var dnsParserPool = &sync.Pool{
|
var dnsParserPool = &sync.Pool{
|
||||||
New: func() interface{} {
|
New: func() any {
|
||||||
return new(dnsParser)
|
return new(dnsParser)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -221,7 +221,7 @@ func weirdoGoCNAMEHandler(target string) dns.HandlerFunc {
|
|||||||
// provided.
|
// provided.
|
||||||
//
|
//
|
||||||
// Types supported: netaddr.IP.
|
// Types supported: netaddr.IP.
|
||||||
func dnsHandler(answers ...interface{}) dns.HandlerFunc {
|
func dnsHandler(answers ...any) dns.HandlerFunc {
|
||||||
return func(w dns.ResponseWriter, req *dns.Msg) {
|
return func(w dns.ResponseWriter, req *dns.Msg) {
|
||||||
m := new(dns.Msg)
|
m := new(dns.Msg)
|
||||||
m.SetReply(req)
|
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 {
|
if len(records)%2 != 0 {
|
||||||
panic("must have an even number of record values")
|
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.
|
// intend to handle responses this large, so there should be truncation.
|
||||||
hugeTXT := generateTXT(64000, randSource)
|
hugeTXT := generateTXT(64000, randSource)
|
||||||
|
|
||||||
records := []interface{}{
|
records := []any{
|
||||||
"test.site.",
|
"test.site.",
|
||||||
resolveToIP(testipv4, testipv6, "dns.test.site."),
|
resolveToIP(testipv4, testipv6, "dns.test.site."),
|
||||||
"LCtesT.SiTe.",
|
"LCtesT.SiTe.",
|
||||||
@ -1105,7 +1105,7 @@ func TestHandleExitNodeDNSQueryWithNetPkg(t *testing.T) {
|
|||||||
t.Skip("skipping test on Windows; waiting for golang.org/issue/33097")
|
t.Skip("skipping test on Windows; waiting for golang.org/issue/33097")
|
||||||
}
|
}
|
||||||
|
|
||||||
records := []interface{}{
|
records := []any{
|
||||||
"no-records.test.",
|
"no-records.test.",
|
||||||
dnsHandler(),
|
dnsHandler(),
|
||||||
|
|
||||||
|
@ -129,7 +129,7 @@ func (r *Resolver) LookupIP(ctx context.Context, host string) (ip, v6 net.IP, al
|
|||||||
ip, ip6 net.IP
|
ip, ip6 net.IP
|
||||||
allIPs []net.IPAddr
|
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)
|
ip, ip6, allIPs, err := r.lookupIP(host)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -103,7 +103,7 @@ type msgResource struct {
|
|||||||
var ErrCacheMiss = errors.New("cache miss")
|
var ErrCacheMiss = errors.New("cache miss")
|
||||||
|
|
||||||
var parserPool = &sync.Pool{
|
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,
|
// ReplyFromCache writes a DNS reply to w for the provided DNS query message,
|
||||||
|
@ -118,17 +118,17 @@ type responseOpt bool
|
|||||||
|
|
||||||
type ttlOpt uint32
|
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))
|
opt = append(opt, responseOpt(false))
|
||||||
return makeDNSPkt(txID, name, opt...)
|
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))
|
opt = append(opt, responseOpt(true))
|
||||||
return makeDNSPkt(txID, name, opt...)
|
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
|
typ := dnsmessage.TypeA
|
||||||
class := dnsmessage.ClassINET
|
class := dnsmessage.ClassINET
|
||||||
var response bool
|
var response bool
|
||||||
|
@ -46,7 +46,7 @@ type Cache struct {
|
|||||||
// entry is the container/list element type.
|
// entry is the container/list element type.
|
||||||
type entry struct {
|
type entry struct {
|
||||||
key Tuple
|
key Tuple
|
||||||
value interface{}
|
value any
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add adds a value to the cache, set or updating its associated
|
// 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
|
// If MaxEntries is non-zero and the length of the cache is greater
|
||||||
// after any addition, the least recently used value is evicted.
|
// 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 {
|
if c.m == nil {
|
||||||
c.m = make(map[Tuple]*list.Element)
|
c.m = make(map[Tuple]*list.Element)
|
||||||
c.ll = list.New()
|
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
|
// Get looks up a key's value from the cache, also reporting
|
||||||
// whether it was present.
|
// 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 {
|
if ele, hit := c.m[key]; hit {
|
||||||
c.ll.MoveToFront(ele)
|
c.ll.MoveToFront(ele)
|
||||||
return ele.Value.(*entry).value, true
|
return ele.Value.(*entry).value, true
|
||||||
|
@ -25,7 +25,7 @@ func TestCache(t *testing.T) {
|
|||||||
t.Fatalf("Len = %d; want %d", got, want)
|
t.Fatalf("Len = %d; want %d", got, want)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
wantVal := func(key Tuple, want interface{}) {
|
wantVal := func(key Tuple, want any) {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
got, ok := c.Get(key)
|
got, ok := c.Get(key)
|
||||||
if !ok {
|
if !ok {
|
||||||
|
@ -191,7 +191,7 @@ func (c *Client) enoughRegions() int {
|
|||||||
return 3
|
return 3
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) logf(format string, a ...interface{}) {
|
func (c *Client) logf(format string, a ...any) {
|
||||||
if c.Logf != nil {
|
if c.Logf != nil {
|
||||||
c.Logf(format, a...)
|
c.Logf(format, a...)
|
||||||
} else {
|
} 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 {
|
if c.Verbose || debugNetcheck {
|
||||||
c.logf(format, a...)
|
c.logf(format, a...)
|
||||||
}
|
}
|
||||||
|
@ -119,7 +119,7 @@ func TestWorksWhenUDPBlocked(t *testing.T) {
|
|||||||
|
|
||||||
func TestAddReportHistoryAndSetPreferredDERP(t *testing.T) {
|
func TestAddReportHistoryAndSetPreferredDERP(t *testing.T) {
|
||||||
// report returns a *Report from (DERP host, time.Duration)+ pairs.
|
// 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{}}
|
r := &Report{RegionLatency: map[int]time.Duration{}}
|
||||||
for i := 0; i < len(a); i += 2 {
|
for i := 0; i < len(a); i += 2 {
|
||||||
s := a[i].(string)
|
s := a[i].(string)
|
||||||
@ -606,7 +606,7 @@ func TestLogConciseReport(t *testing.T) {
|
|||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
var buf bytes.Buffer
|
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)
|
c.logConciseReport(tt.r, dm)
|
||||||
if got := strings.TrimPrefix(buf.String(), "[v1] report: "); got != tt.want {
|
if got := strings.TrimPrefix(buf.String(), "[v1] report: "); got != tt.want {
|
||||||
t.Errorf("unexpected result.\n got: %#q\nwant: %#q\n", got, tt.want)
|
t.Errorf("unexpected result.\n got: %#q\nwant: %#q\n", got, tt.want)
|
||||||
|
@ -15,7 +15,7 @@ import (
|
|||||||
"inet.af/netaddr"
|
"inet.af/netaddr"
|
||||||
)
|
)
|
||||||
|
|
||||||
type upnpClient interface{}
|
type upnpClient any
|
||||||
|
|
||||||
type uPnPDiscoResponse struct{}
|
type uPnPDiscoResponse struct{}
|
||||||
|
|
||||||
|
@ -67,7 +67,7 @@ func NewTestIGD(logf logger.Logf, t TestIGDOptions) (*TestIGD, error) {
|
|||||||
doPCP: t.PCP,
|
doPCP: t.PCP,
|
||||||
doUPnP: t.UPnP,
|
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;
|
// Don't log after the device has closed;
|
||||||
// stray trailing logging angers testing.T.Logf.
|
// stray trailing logging angers testing.T.Logf.
|
||||||
if d.closed.Get() {
|
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)
|
return dial(ctx, network, addr)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) logf(format string, args ...interface{}) {
|
func (s *Server) logf(format string, args ...any) {
|
||||||
logf := s.Logf
|
logf := s.Logf
|
||||||
if logf == nil {
|
if logf == nil {
|
||||||
logf = log.Printf
|
logf = log.Printf
|
||||||
|
@ -60,7 +60,7 @@ var (
|
|||||||
// parsedPacketPool holds a pool of Parsed structs for use in filtering.
|
// parsedPacketPool holds a pool of Parsed structs for use in filtering.
|
||||||
// This is needed because escape analysis cannot see that parsed packets
|
// This is needed because escape analysis cannot see that parsed packets
|
||||||
// do not escape through {Pre,Post}Filter{In,Out}.
|
// 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.
|
// 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.
|
// 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 {
|
matchField := func(name string) func(p cmp.Path) bool {
|
||||||
return func(p cmp.Path) bool {
|
return func(p cmp.Path) bool {
|
||||||
if len(p) != 3 {
|
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) Done() <-chan struct{} { return ctx.done }
|
||||||
func (ctx *sshContext) Deadline() (deadline time.Time, ok bool) { return }
|
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
|
// userVisibleError is a wrapper around an error that implements
|
||||||
// SSHTerminationError, so msg is written to their session.
|
// 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.
|
// callLogin1 invokes the provided method of the "login1" service over D-Bus.
|
||||||
// https://www.freedesktop.org/software/systemd/man/org.freedesktop.login1.html
|
// 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()
|
conn, err := dbus.SystemBus()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// DBus probably not running.
|
// DBus probably not running.
|
||||||
@ -77,8 +77,8 @@ type createSessionArgs struct {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a createSessionArgs) args() []interface{} {
|
func (a createSessionArgs) args() []any {
|
||||||
return []interface{}{
|
return []any{
|
||||||
a.uid,
|
a.uid,
|
||||||
a.pid,
|
a.pid,
|
||||||
a.service,
|
a.service,
|
||||||
|
@ -326,7 +326,7 @@ var _DERPNodeCloneNeedsRegeneration = DERPNode(struct {
|
|||||||
// Clone duplicates src into dst and reports whether it succeeded.
|
// Clone duplicates src into dst and reports whether it succeeded.
|
||||||
// To succeed, <src, dst> must be of types <*T, *T> or <*T, **T>,
|
// 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.
|
// 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) {
|
switch src := src.(type) {
|
||||||
case *User:
|
case *User:
|
||||||
switch dst := dst.(type) {
|
switch dst := dst.(type) {
|
||||||
|
@ -189,7 +189,7 @@ func (ap *AuthPath) CompleteSuccessfully() {
|
|||||||
ap.closeOnce.Do(ap.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 {
|
if s.Logf != nil {
|
||||||
s.Logf(format, a...)
|
s.Logf(format, a...)
|
||||||
} else {
|
} else {
|
||||||
@ -779,7 +779,7 @@ func (s *Server) MapResponse(req *tailcfg.MapRequest) (res *tailcfg.MapResponse,
|
|||||||
return res, nil
|
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)
|
resBytes, err := s.encode(mkey, compress, msg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -803,7 +803,7 @@ func (s *Server) sendMapMsg(w http.ResponseWriter, mkey key.MachinePublic, compr
|
|||||||
return nil
|
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 {
|
if len(msg) == msgLimit {
|
||||||
return errors.New("encrypted message too long")
|
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{
|
var zstdEncoderPool = &sync.Pool{
|
||||||
New: func() interface{} {
|
New: func() any {
|
||||||
encoder, err := smallzstd.NewEncoder(nil, zstd.WithEncoderLevel(zstd.SpeedFastest))
|
encoder, err := smallzstd.NewEncoder(nil, zstd.WithEncoderLevel(zstd.SpeedFastest))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
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
|
var isBytes bool
|
||||||
if b, isBytes = v.([]byte); !isBytes {
|
if b, isBytes = v.([]byte); !isBytes {
|
||||||
b, err = json.Marshal(v)
|
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.
|
// 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()
|
lt.mu.Lock()
|
||||||
if lt.closed {
|
if lt.closed {
|
||||||
lt.mu.Unlock()
|
lt.mu.Unlock()
|
||||||
@ -131,7 +131,7 @@ type MemLogger struct {
|
|||||||
bytes.Buffer
|
bytes.Buffer
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ml *MemLogger) Logf(format string, args ...interface{}) {
|
func (ml *MemLogger) Logf(format string, args ...any) {
|
||||||
ml.Lock()
|
ml.Lock()
|
||||||
defer ml.Unlock()
|
defer ml.Unlock()
|
||||||
fmt.Fprintf(&ml.Buffer, format, args...)
|
fmt.Fprintf(&ml.Buffer, format, args...)
|
||||||
|
@ -66,16 +66,16 @@ func (p *Packet) short() string {
|
|||||||
return fmt.Sprintf("%s/%s", payload, tuple)
|
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 {
|
if !traceOn {
|
||||||
return
|
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...)
|
allArgs = append(allArgs, args...)
|
||||||
fmt.Fprintf(os.Stderr, "[%s]%s src=%s dst=%s "+msg+"\n", allArgs...)
|
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...)
|
p.locator = fmt.Sprintf(" "+msg, args...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,7 +52,7 @@ func Debugger(mux *http.ServeMux) *DebugHandler {
|
|||||||
// index page. The /pprof/ index already covers it.
|
// index page. The /pprof/ index already covers it.
|
||||||
mux.Handle("/debug/pprof/profile", http.HandlerFunc(pprof.Profile))
|
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.KV("Version", version.Long)
|
||||||
ret.Handle("vars", "Metrics (Go)", expvar.Handler())
|
ret.Handle("vars", "Metrics (Go)", expvar.Handler())
|
||||||
ret.Handle("varz", "Metrics (Prometheus)", http.HandlerFunc(VarzHandler))
|
ret.Handle("varz", "Metrics (Prometheus)", http.HandlerFunc(VarzHandler))
|
||||||
@ -79,7 +79,7 @@ func (d *DebugHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
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())
|
f("<html><body><h1>%s debug</h1><ul>", version.CmdName())
|
||||||
for _, kv := range d.kvs {
|
for _, kv := range d.kvs {
|
||||||
kv(w)
|
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/.
|
// 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))
|
val := html.EscapeString(fmt.Sprintf("%v", v))
|
||||||
d.kvs = append(d.kvs, func(w io.Writer) {
|
d.kvs = append(d.kvs, func(w io.Writer) {
|
||||||
fmt.Fprintf(w, "<li><b>%s:</b> %s</li>", k, val)
|
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
|
// KVFunc adds a key/value list item to /debug/. v is called on every
|
||||||
// render of /debug/.
|
// 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) {
|
d.kvs = append(d.kvs, func(w io.Writer) {
|
||||||
val := html.EscapeString(fmt.Sprintf("%v", v()))
|
val := html.EscapeString(fmt.Sprintf("%v", v()))
|
||||||
fmt.Fprintf(w, "<li><b>%s:</b> %s</li>", k, val)
|
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("Donuts", 42)
|
||||||
dbg.KV("Secret code", "hunter2")
|
dbg.KV("Secret code", "hunter2")
|
||||||
val := "red"
|
val := "red"
|
||||||
dbg.KVFunc("Condition", func() interface{} { return val })
|
dbg.KVFunc("Condition", func() any { return val })
|
||||||
|
|
||||||
code, _ := get(mux, "/debug/", pubIP)
|
code, _ := get(mux, "/debug/", pubIP)
|
||||||
if code != 403 {
|
if code != 403 {
|
||||||
@ -183,7 +183,7 @@ func ExampleDebugHandler_KVFunc() {
|
|||||||
// Adds an count of page renders to /debug/. Note this example
|
// Adds an count of page renders to /debug/. Note this example
|
||||||
// isn't concurrency-safe.
|
// isn't concurrency-safe.
|
||||||
views := 0
|
views := 0
|
||||||
dbg.KVFunc("Debug pageviews", func() interface{} {
|
dbg.KVFunc("Debug pageviews", func() any {
|
||||||
views = views + 1
|
views = views + 1
|
||||||
return views
|
return views
|
||||||
})
|
})
|
||||||
|
@ -19,16 +19,16 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type response struct {
|
type response struct {
|
||||||
Status string `json:"status"`
|
Status string `json:"status"`
|
||||||
Error string `json:"error,omitempty"`
|
Error string `json:"error,omitempty"`
|
||||||
Data interface{} `json:"data,omitempty"`
|
Data any `json:"data,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// JSONHandlerFunc is an HTTP ReturnHandler that writes JSON responses to the client.
|
// JSONHandlerFunc is an HTTP ReturnHandler that writes JSON responses to the client.
|
||||||
//
|
//
|
||||||
// Return a HTTPError to show an error message, otherwise JSONHandlerFunc will
|
// Return a HTTPError to show an error message, otherwise JSONHandlerFunc will
|
||||||
// only report "internal server error" to the user with status code 500.
|
// 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.
|
// ServeHTTPReturn implements the ReturnHandler interface.
|
||||||
//
|
//
|
||||||
|
@ -71,7 +71,7 @@ func TestNewJSONHandler(t *testing.T) {
|
|||||||
return d
|
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
|
return http.StatusOK, nil, nil
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -83,7 +83,7 @@ func TestNewJSONHandler(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
t.Run("403 HTTPError", func(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)
|
return 0, nil, Error(http.StatusForbidden, "forbidden", nil)
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -93,7 +93,7 @@ func TestNewJSONHandler(t *testing.T) {
|
|||||||
checkStatus(t, w, "error", http.StatusForbidden)
|
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
|
return http.StatusOK, &Data{Name: "tailscale"}, nil
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -104,7 +104,7 @@ func TestNewJSONHandler(t *testing.T) {
|
|||||||
checkStatus(t, w, "success", http.StatusOK)
|
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)
|
body := new(Data)
|
||||||
if err := json.NewDecoder(r.Body).Decode(body); err != nil {
|
if err := json.NewDecoder(r.Body).Decode(body); err != nil {
|
||||||
return 0, nil, Error(http.StatusBadRequest, err.Error(), err)
|
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)
|
body := new(Data)
|
||||||
if err := json.NewDecoder(r.Body).Decode(body); err != nil {
|
if err := json.NewDecoder(r.Body).Decode(body); err != nil {
|
||||||
return 0, nil, Error(http.StatusBadRequest, err.Error(), err)
|
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 := httptest.NewRequest("POST", "/", strings.NewReader(`{"Price": 10}`))
|
||||||
r.Header.Set("Accept-Encoding", "gzip")
|
r.Header.Set("Accept-Encoding", "gzip")
|
||||||
value := []string{"foo", "foo", "foo"}
|
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
|
return 400, value, nil
|
||||||
}).ServeHTTPReturn(w, r)
|
}).ServeHTTPReturn(w, r)
|
||||||
res := w.Result()
|
res := w.Result()
|
||||||
@ -222,7 +222,7 @@ func TestNewJSONHandler(t *testing.T) {
|
|||||||
t.Run("500 misuse", func(t *testing.T) {
|
t.Run("500 misuse", func(t *testing.T) {
|
||||||
w := httptest.NewRecorder()
|
w := httptest.NewRecorder()
|
||||||
r := httptest.NewRequest("POST", "/", nil)
|
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
|
return http.StatusOK, make(chan int), nil
|
||||||
}).ServeHTTPReturn(w, r)
|
}).ServeHTTPReturn(w, r)
|
||||||
resp := checkStatus(t, w, "error", http.StatusInternalServerError)
|
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) {
|
t.Run("500 empty status code", func(t *testing.T) {
|
||||||
w := httptest.NewRecorder()
|
w := httptest.NewRecorder()
|
||||||
r := httptest.NewRequest("POST", "/", nil)
|
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
|
return
|
||||||
}).ServeHTTPReturn(w, r)
|
}).ServeHTTPReturn(w, r)
|
||||||
checkStatus(t, w, "error", http.StatusInternalServerError)
|
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) {
|
t.Run("403 forbidden, status returned by JSONHandlerFunc and HTTPError agree", func(t *testing.T) {
|
||||||
w := httptest.NewRecorder()
|
w := httptest.NewRecorder()
|
||||||
r := httptest.NewRequest("POST", "/", nil)
|
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)
|
return http.StatusForbidden, nil, Error(http.StatusForbidden, "403 forbidden", nil)
|
||||||
}).ServeHTTPReturn(w, r)
|
}).ServeHTTPReturn(w, r)
|
||||||
want := &Response{
|
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) {
|
t.Run("403 forbidden, status returned by JSONHandlerFunc and HTTPError do not agree", func(t *testing.T) {
|
||||||
w := httptest.NewRecorder()
|
w := httptest.NewRecorder()
|
||||||
r := httptest.NewRequest("POST", "/", nil)
|
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)
|
return http.StatusInternalServerError, nil, Error(http.StatusForbidden, "403 forbidden", nil)
|
||||||
}).ServeHTTPReturn(w, r)
|
}).ServeHTTPReturn(w, r)
|
||||||
if !strings.HasPrefix(err.Error(), "[unexpected]") {
|
if !strings.HasPrefix(err.Error(), "[unexpected]") {
|
||||||
|
@ -33,10 +33,10 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
expvar.Publish("process_start_unix_time", expvar.Func(func() interface{} { return timeStart.Unix() }))
|
expvar.Publish("process_start_unix_time", expvar.Func(func() any { return timeStart.Unix() }))
|
||||||
expvar.Publish("version", expvar.Func(func() interface{} { return version.Long }))
|
expvar.Publish("version", expvar.Func(func() any { return version.Long }))
|
||||||
expvar.Publish("counter_uptime_sec", expvar.Func(func() interface{} { return int64(Uptime().Seconds()) }))
|
expvar.Publish("counter_uptime_sec", expvar.Func(func() any { return int64(Uptime().Seconds()) }))
|
||||||
expvar.Publish("gauge_goroutines", expvar.Func(func() interface{} { return runtime.NumGoroutine() }))
|
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.
|
// 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
|
expvar.Var
|
||||||
|
|
||||||
// PrometheusMetricsReflectRoot returns the struct or struct pointer to walk.
|
// PrometheusMetricsReflectRoot returns the struct or struct pointer to walk.
|
||||||
PrometheusMetricsReflectRoot() interface{}
|
PrometheusMetricsReflectRoot() any
|
||||||
}
|
}
|
||||||
|
|
||||||
var expvarDo = expvar.Do // pulled out for tests
|
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) PrometheusMetricsReflectRoot() any { return r.v }
|
||||||
func (r expVarPromStructRoot) String() string { panic("unused") }
|
func (r expVarPromStructRoot) String() string { panic("unused") }
|
||||||
|
|
||||||
var (
|
var (
|
||||||
_ PrometheusMetricsReflectRooter = expVarPromStructRoot{}
|
_ PrometheusMetricsReflectRooter = expVarPromStructRoot{}
|
||||||
|
@ -241,7 +241,7 @@ func TestStdHandler(t *testing.T) {
|
|||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
t.Run(test.name, func(t *testing.T) {
|
t.Run(test.name, func(t *testing.T) {
|
||||||
var logs []AccessLogRecord
|
var logs []AccessLogRecord
|
||||||
logf := func(fmt string, args ...interface{}) {
|
logf := func(fmt string, args ...any) {
|
||||||
if fmt == "%s" {
|
if fmt == "%s" {
|
||||||
logs = append(logs, args[0].(AccessLogRecord))
|
logs = append(logs, args[0].(AccessLogRecord))
|
||||||
}
|
}
|
||||||
@ -378,19 +378,19 @@ func TestVarzHandler(t *testing.T) {
|
|||||||
{
|
{
|
||||||
"func_float64",
|
"func_float64",
|
||||||
"counter_x",
|
"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",
|
"# TYPE x counter\nx 1.2\n",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"func_float64_gauge",
|
"func_float64_gauge",
|
||||||
"gauge_x",
|
"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",
|
"# TYPE x gauge\nx 1.2\n",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"func_float64_untyped",
|
"func_float64_untyped",
|
||||||
"x",
|
"x",
|
||||||
expvar.Func(func() interface{} { return float64(1.2) }),
|
expvar.Func(func() any { return float64(1.2) }),
|
||||||
"x 1.2\n",
|
"x 1.2\n",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -466,7 +466,7 @@ foo_AUint16 65535
|
|||||||
{
|
{
|
||||||
"func_returning_int",
|
"func_returning_int",
|
||||||
"num_goroutines",
|
"num_goroutines",
|
||||||
expvar.Func(func() interface{} { return 123 }),
|
expvar.Func(func() any { return 123 }),
|
||||||
"num_goroutines 123\n",
|
"num_goroutines 123\n",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@ -531,6 +531,6 @@ type expvarAdapter struct {
|
|||||||
|
|
||||||
func (expvarAdapter) String() string { return "{}" } // expvar JSON; unused in test
|
func (expvarAdapter) String() string { return "{}" } // expvar JSON; unused in test
|
||||||
|
|
||||||
func (a expvarAdapter) PrometheusMetricsReflectRoot() interface{} {
|
func (a expvarAdapter) PrometheusMetricsReflectRoot() any {
|
||||||
return a.st
|
return a.st
|
||||||
}
|
}
|
||||||
|
@ -32,7 +32,7 @@ var _ResolverCloneNeedsRegeneration = Resolver(struct {
|
|||||||
// Clone duplicates src into dst and reports whether it succeeded.
|
// Clone duplicates src into dst and reports whether it succeeded.
|
||||||
// To succeed, <src, dst> must be of types <*T, *T> or <*T, **T>,
|
// To succeed, <src, dst> must be of types <*T, *T> or <*T, **T>,
|
||||||
// where T is one of Resolver.
|
// where T is one of Resolver.
|
||||||
func Clone(dst, src interface{}) bool {
|
func Clone(dst, src any) bool {
|
||||||
switch src := src.(type) {
|
switch src := src.(type) {
|
||||||
case *Resolver:
|
case *Resolver:
|
||||||
switch dst := dst.(type) {
|
switch dst := dst.(type) {
|
||||||
|
@ -28,7 +28,7 @@ import (
|
|||||||
// Logf is the basic Tailscale logger type: a printf-like func.
|
// Logf is the basic Tailscale logger type: a printf-like func.
|
||||||
// Like log.Printf, the format need not end in a newline.
|
// Like log.Printf, the format need not end in a newline.
|
||||||
// Logf functions must be safe for concurrent use.
|
// 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.
|
// 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.
|
// If no log function is present, FromContext will return log.Printf.
|
||||||
@ -43,7 +43,7 @@ type jenc struct {
|
|||||||
enc *json.Encoder
|
enc *json.Encoder
|
||||||
}
|
}
|
||||||
|
|
||||||
var jencPool = &sync.Pool{New: func() interface{} {
|
var jencPool = &sync.Pool{New: func() any {
|
||||||
je := new(jenc)
|
je := new(jenc)
|
||||||
je.enc = json.NewEncoder(&je.buf)
|
je.enc = json.NewEncoder(&je.buf)
|
||||||
return je
|
return je
|
||||||
@ -61,7 +61,7 @@ var jencPool = &sync.Pool{New: func() interface{} {
|
|||||||
//
|
//
|
||||||
// The level can be from 0 to 9. Levels from 1 to 9 are included in
|
// The level can be from 0 to 9. Levels from 1 to 9 are included in
|
||||||
// the logged JSON object, like {"foo":123,"v":2}.
|
// 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)
|
je := jencPool.Get().(*jenc)
|
||||||
defer jencPool.Put(je)
|
defer jencPool.Put(je)
|
||||||
je.buf.Reset()
|
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.
|
// WithPrefix wraps f, prefixing each format with the provided prefix.
|
||||||
func WithPrefix(f Logf, prefix string) Logf {
|
func WithPrefix(f Logf, prefix string) Logf {
|
||||||
return func(format string, args ...interface{}) {
|
return func(format string, args ...any) {
|
||||||
f(prefix+format, args...)
|
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.
|
// 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
|
// limitData is used to keep track of each format string's associated
|
||||||
// rate-limiting data.
|
// 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
|
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
|
// Shortcut for formats with no rate limit
|
||||||
for _, sub := range rateFree {
|
for _, sub := range rateFree {
|
||||||
if strings.Contains(format, sub) {
|
if strings.Contains(format, sub) {
|
||||||
@ -239,7 +239,7 @@ func LogOnChange(logf Logf, maxInterval time.Duration, timeNow func() time.Time)
|
|||||||
tLastLogged = timeNow()
|
tLastLogged = timeNow()
|
||||||
)
|
)
|
||||||
|
|
||||||
return func(format string, args ...interface{}) {
|
return func(format string, args ...any) {
|
||||||
s := fmt.Sprintf(format, args...)
|
s := fmt.Sprintf(format, args...)
|
||||||
|
|
||||||
mu.Lock()
|
mu.Lock()
|
||||||
@ -270,13 +270,13 @@ func (fn ArgWriter) Format(f fmt.State, _ rune) {
|
|||||||
argBufioPool.Put(bw)
|
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.
|
// Filtered returns a Logf that silently swallows some log lines.
|
||||||
// Each inbound format and args is evaluated and printed to a string s.
|
// 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.
|
// 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 {
|
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...)
|
msg := fmt.Sprintf(format, args...)
|
||||||
if !allow(msg) {
|
if !allow(msg) {
|
||||||
return
|
return
|
||||||
@ -297,7 +297,7 @@ func LogfCloser(logf Logf) (newLogf Logf, close func()) {
|
|||||||
defer mu.Unlock()
|
defer mu.Unlock()
|
||||||
closed = true
|
closed = true
|
||||||
}
|
}
|
||||||
newLogf = func(msg string, args ...interface{}) {
|
newLogf = func(msg string, args ...any) {
|
||||||
mu.Lock()
|
mu.Lock()
|
||||||
if closed {
|
if closed {
|
||||||
mu.Unlock()
|
mu.Unlock()
|
||||||
|
@ -30,7 +30,7 @@ func TestStdLogger(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func logTester(want []string, t *testing.T, i *int) Logf {
|
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...)
|
got := fmt.Sprintf(format, args...)
|
||||||
if *i >= len(want) {
|
if *i >= len(want) {
|
||||||
t.Fatalf("Logging continued past end of expected input: %s", got)
|
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.
|
// Test that FromContext and Ctx work together.
|
||||||
var called bool
|
var called bool
|
||||||
markCalled := func(string, ...interface{}) {
|
markCalled := func(string, ...any) {
|
||||||
called = true
|
called = true
|
||||||
}
|
}
|
||||||
ctx = Ctx(ctx, markCalled)
|
ctx = Ctx(ctx, markCalled)
|
||||||
@ -215,7 +215,7 @@ func TestContext(t *testing.T) {
|
|||||||
|
|
||||||
func TestJSON(t *testing.T) {
|
func TestJSON(t *testing.T) {
|
||||||
var buf bytes.Buffer
|
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{})
|
logf.JSON(1, "foo", &tailcfg.Hostinfo{})
|
||||||
want := "[v\x00JSON]1" + `{"foo":{"OS":"","Hostname":""}}`
|
want := "[v\x00JSON]1" + `{"foo":{"OS":"","Hostname":""}}`
|
||||||
if got := buf.String(); got != want {
|
if got := buf.String(); got != want {
|
||||||
|
@ -13,7 +13,7 @@ import (
|
|||||||
// a prefixed log message to each line with the current binary memory usage
|
// a prefixed log message to each line with the current binary memory usage
|
||||||
// and max RSS.
|
// and max RSS.
|
||||||
func RusagePrefixLog(logf Logf) Logf {
|
func RusagePrefixLog(logf Logf) Logf {
|
||||||
return func(f string, argv ...interface{}) {
|
return func(f string, argv ...any) {
|
||||||
var m runtime.MemStats
|
var m runtime.MemStats
|
||||||
runtime.ReadMemStats(&m)
|
runtime.ReadMemStats(&m)
|
||||||
goMem := float64(m.HeapInuse+m.StackInuse) / (1 << 20)
|
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.
|
// Scan implements database/sql.Scanner.
|
||||||
func (b *Bool) Scan(src interface{}) error {
|
func (b *Bool) Scan(src any) error {
|
||||||
if src == nil {
|
if src == nil {
|
||||||
*b = ""
|
*b = ""
|
||||||
return nil
|
return nil
|
||||||
|
@ -13,7 +13,7 @@ import (
|
|||||||
func TestBool(t *testing.T) {
|
func TestBool(t *testing.T) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
in interface{}
|
in any
|
||||||
want string // JSON
|
want string // JSON
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
|
@ -256,7 +256,7 @@ func EncodeLogTailMetricsDelta() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var deltaPool = &sync.Pool{
|
var deltaPool = &sync.Pool{
|
||||||
New: func() interface{} {
|
New: func() any {
|
||||||
return new(deltaEncBuf)
|
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.
|
// 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 {
|
func AssertStructUnchanged(t *types.Struct, thisPkg *types.Package, tname, ctx string, imports map[string]struct{}) []byte {
|
||||||
buf := new(bytes.Buffer)
|
buf := new(bytes.Buffer)
|
||||||
w := func(format string, args ...interface{}) {
|
w := func(format string, args ...any) {
|
||||||
fmt.Fprintf(buf, format+"\n", args...)
|
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.")
|
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{
|
var hasherPool = &sync.Pool{
|
||||||
New: func() interface{} { return new(hasher) },
|
New: func() any { return new(hasher) },
|
||||||
}
|
}
|
||||||
|
|
||||||
// Hash returns the hash of v.
|
// Hash returns the hash of v.
|
||||||
func Hash(v interface{}) (s Sum) {
|
func Hash(v any) (s Sum) {
|
||||||
h := hasherPool.Get().(*hasher)
|
h := hasherPool.Get().(*hasher)
|
||||||
defer hasherPool.Put(h)
|
defer hasherPool.Put(h)
|
||||||
h.reset()
|
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.
|
// 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)
|
sum := Hash(v)
|
||||||
if sum == *last {
|
if sum == *last {
|
||||||
// unchanged.
|
// unchanged.
|
||||||
@ -304,7 +304,7 @@ type mapHasher struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var mapHasherPool = &sync.Pool{
|
var mapHasherPool = &sync.Pool{
|
||||||
New: func() interface{} { return new(mapHasher) },
|
New: func() any { return new(mapHasher) },
|
||||||
}
|
}
|
||||||
|
|
||||||
type valueCache map[reflect.Type]reflect.Value
|
type valueCache map[reflect.Type]reflect.Value
|
||||||
|
@ -35,8 +35,8 @@ func (p appendBytes) AppendTo(b []byte) []byte {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestHash(t *testing.T) {
|
func TestHash(t *testing.T) {
|
||||||
type tuple [2]interface{}
|
type tuple [2]any
|
||||||
type iface struct{ X interface{} }
|
type iface struct{ X any }
|
||||||
type scalars struct {
|
type scalars struct {
|
||||||
I8 int8
|
I8 int8
|
||||||
I16 int16
|
I16 int16
|
||||||
@ -132,8 +132,8 @@ func TestDeepHash(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func getVal() []interface{} {
|
func getVal() []any {
|
||||||
return []interface{}{
|
return []any{
|
||||||
&wgcfg.Config{
|
&wgcfg.Config{
|
||||||
Name: "foo",
|
Name: "foo",
|
||||||
Addresses: []netaddr.IPPrefix{netaddr.IPPrefixFrom(netaddr.IPFrom16([16]byte{3: 3}), 5)},
|
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)
|
// verify this doesn't loop forever, as it used to (Issue 2340)
|
||||||
func TestMapCyclicFallback(t *testing.T) {
|
func TestMapCyclicFallback(t *testing.T) {
|
||||||
type T struct {
|
type T struct {
|
||||||
M map[string]interface{}
|
M map[string]any
|
||||||
}
|
}
|
||||||
v := &T{
|
v := &T{
|
||||||
M: map[string]interface{}{},
|
M: map[string]any{},
|
||||||
}
|
}
|
||||||
v.M["m"] = v.M
|
v.M["m"] = v.M
|
||||||
Hash(v)
|
Hash(v)
|
||||||
|
@ -20,13 +20,13 @@ type decoder struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var readerPool = sync.Pool{
|
var readerPool = sync.Pool{
|
||||||
New: func() interface{} {
|
New: func() any {
|
||||||
return bytes.NewReader(nil)
|
return bytes.NewReader(nil)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
var decoderPool = sync.Pool{
|
var decoderPool = sync.Pool{
|
||||||
New: func() interface{} {
|
New: func() any {
|
||||||
var d decoder
|
var d decoder
|
||||||
d.r = readerPool.Get().(*bytes.Reader)
|
d.r = readerPool.Get().(*bytes.Reader)
|
||||||
d.dec = json.NewDecoder(d.r)
|
d.dec = json.NewDecoder(d.r)
|
||||||
@ -47,7 +47,7 @@ var decoderPool = sync.Pool{
|
|||||||
// don't use this Unmarshal.
|
// don't use this Unmarshal.
|
||||||
//
|
//
|
||||||
// This Unmarshal allocates considerably less memory.
|
// 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 := decoderPool.Get().(*decoder)
|
||||||
d.r.Reset(b)
|
d.r.Reset(b)
|
||||||
off := d.dec.InputOffset()
|
off := d.dec.InputOffset()
|
||||||
|
@ -27,7 +27,7 @@ func TestCompareToStd(t *testing.T) {
|
|||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
b := []byte(test)
|
b := []byte(test)
|
||||||
var ourV, stdV interface{}
|
var ourV, stdV any
|
||||||
ourErr := Unmarshal(b, &ourV)
|
ourErr := Unmarshal(b, &ourV)
|
||||||
stdErr := json.Unmarshal(b, &stdV)
|
stdErr := json.Unmarshal(b, &stdV)
|
||||||
if (ourErr == nil) != (stdErr == nil) {
|
if (ourErr == nil) != (stdErr == nil) {
|
||||||
@ -47,7 +47,7 @@ func TestCompareToStd(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkUnmarshal(b *testing.B) {
|
func BenchmarkUnmarshal(b *testing.B) {
|
||||||
var m interface{}
|
var m any
|
||||||
j := []byte("5")
|
j := []byte("5")
|
||||||
b.ReportAllocs()
|
b.ReportAllocs()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
@ -56,7 +56,7 @@ func BenchmarkUnmarshal(b *testing.B) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkStdUnmarshal(b *testing.B) {
|
func BenchmarkStdUnmarshal(b *testing.B) {
|
||||||
var m interface{}
|
var m any
|
||||||
j := []byte("5")
|
j := []byte("5")
|
||||||
b.ReportAllocs()
|
b.ReportAllocs()
|
||||||
for i := 0; i < b.N; i++ {
|
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,
|
// 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.
|
// 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 {
|
for _, err := range e.errs {
|
||||||
if ok := errors.As(err, target); ok {
|
if ok := errors.As(err, target); ok {
|
||||||
return true
|
return true
|
||||||
|
@ -25,7 +25,7 @@ type logOnce struct {
|
|||||||
sync.Once
|
sync.Once
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *logOnce) logf(format string, args ...interface{}) {
|
func (l *logOnce) logf(format string, args ...any) {
|
||||||
l.Once.Do(func() {
|
l.Once.Do(func() {
|
||||||
log.Printf(format, args...)
|
log.Printf(format, args...)
|
||||||
})
|
})
|
||||||
@ -71,7 +71,7 @@ func Ready() {
|
|||||||
// CPU: 2min 38.469s
|
// CPU: 2min 38.469s
|
||||||
// CGroup: /system.slice/tailscale.service
|
// CGroup: /system.slice/tailscale.service
|
||||||
// └─26741 /nix/store/sv6cj4mw2jajm9xkbwj07k29dj30lh0n-tailscale-date.20200727/bin/tailscaled --port 41641
|
// └─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...))
|
err := notifier().Notify(sdnotify.Statusf(format, args...))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
statusOnce.logf("systemd: error notifying: %v", err)
|
statusOnce.logf("systemd: error notifying: %v", err)
|
||||||
|
@ -7,5 +7,5 @@
|
|||||||
|
|
||||||
package systemd
|
package systemd
|
||||||
|
|
||||||
func Ready() {}
|
func Ready() {}
|
||||||
func Status(string, ...interface{}) {}
|
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.
|
// It adjusts the length of the slice appropriately and zeros the tail.
|
||||||
// eq reports whether (*sliceptr)[i] and (*sliceptr)[j] are equal.
|
// eq reports whether (*sliceptr)[i] and (*sliceptr)[j] are equal.
|
||||||
// ModifySlice does O(len(*sliceptr)) operations.
|
// 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)
|
rvp := reflect.ValueOf(sliceptr)
|
||||||
if rvp.Type().Kind() != reflect.Ptr {
|
if rvp.Type().Kind() != reflect.Ptr {
|
||||||
panic(badTypeError{rvp.Type()})
|
panic(badTypeError{rvp.Type()})
|
||||||
|
@ -276,7 +276,7 @@ func (f *Firewall) permitNDP(w weight) error {
|
|||||||
fieldICMPType := wf.FieldIPLocalPort
|
fieldICMPType := wf.FieldIPLocalPort
|
||||||
fieldICMPCode := wf.FieldIPRemotePort
|
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{
|
conditions := []*wf.Match{
|
||||||
{
|
{
|
||||||
Field: wf.FieldIPProtocol,
|
Field: wf.FieldIPProtocol,
|
||||||
@ -359,7 +359,7 @@ func (f *Firewall) permitNDP(w weight) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (f *Firewall) permitDHCPv6(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{
|
conditions := []*wf.Match{
|
||||||
{
|
{
|
||||||
Field: wf.FieldIPProtocol,
|
Field: wf.FieldIPProtocol,
|
||||||
@ -403,7 +403,7 @@ func (f *Firewall) permitDHCPv6(w weight) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (f *Firewall) permitDHCPv4(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{
|
conditions := []*wf.Match{
|
||||||
{
|
{
|
||||||
Field: wf.FieldIPProtocol,
|
Field: wf.FieldIPProtocol,
|
||||||
|
@ -432,7 +432,7 @@ func TestLoggingPrivacy(t *testing.T) {
|
|||||||
logged bool
|
logged bool
|
||||||
testLogger logger.Logf
|
testLogger logger.Logf
|
||||||
)
|
)
|
||||||
logf := func(format string, args ...interface{}) {
|
logf := func(format string, args ...any) {
|
||||||
testLogger(format, args...)
|
testLogger(format, args...)
|
||||||
logged = true
|
logged = true
|
||||||
}
|
}
|
||||||
|
@ -1197,7 +1197,7 @@ var errDropDerpPacket = errors.New("too many DERP packets queued; dropping")
|
|||||||
var errNoUDP = errors.New("no UDP available on platform")
|
var errNoUDP = errors.New("no UDP available on platform")
|
||||||
|
|
||||||
var udpAddrPool = &sync.Pool{
|
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.
|
// 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()
|
mu.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
logf = func(s string, args ...interface{}) {
|
logf = func(s string, args ...any) {
|
||||||
mu.RLock()
|
mu.RLock()
|
||||||
t := cur
|
t := cur
|
||||||
|
|
||||||
@ -922,7 +922,7 @@ func testActiveDiscovery(t *testing.T, d *devices) {
|
|||||||
setT(t)
|
setT(t)
|
||||||
|
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
wlogf := func(msg string, args ...interface{}) {
|
wlogf := func(msg string, args ...any) {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
msg = fmt.Sprintf("%s: %s", time.Since(start).Truncate(time.Microsecond), msg)
|
msg = fmt.Sprintf("%s: %s", time.Since(start).Truncate(time.Microsecond), msg)
|
||||||
tlogf(msg, args...)
|
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)
|
j, err := json.Marshal(x)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -178,7 +178,7 @@ func ipOfAddr(a route.Addr) netaddr.IP {
|
|||||||
return netaddr.IP{}
|
return netaddr.IP{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func fmtAddr(a route.Addr) interface{} {
|
func fmtAddr(a route.Addr) any {
|
||||||
if a == nil {
|
if a == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,7 @@ import (
|
|||||||
func TestInjectInboundLeak(t *testing.T) {
|
func TestInjectInboundLeak(t *testing.T) {
|
||||||
tunDev := tstun.NewFake()
|
tunDev := tstun.NewFake()
|
||||||
dialer := new(tsdial.Dialer)
|
dialer := new(tsdial.Dialer)
|
||||||
logf := func(format string, args ...interface{}) {
|
logf := func(format string, args ...any) {
|
||||||
if !t.Failed() {
|
if !t.Failed() {
|
||||||
t.Logf(format, args...)
|
t.Logf(format, args...)
|
||||||
}
|
}
|
||||||
|
@ -84,7 +84,7 @@ type netfilterRunner interface {
|
|||||||
|
|
||||||
type linuxRouter struct {
|
type linuxRouter struct {
|
||||||
closed syncs.AtomicBool
|
closed syncs.AtomicBool
|
||||||
logf func(fmt string, args ...interface{})
|
logf func(fmt string, args ...any)
|
||||||
tunname string
|
tunname string
|
||||||
linkMon *monitor.Mon
|
linkMon *monitor.Mon
|
||||||
unregLinkMon func()
|
unregLinkMon func()
|
||||||
|
@ -28,7 +28,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type winRouter struct {
|
type winRouter struct {
|
||||||
logf func(fmt string, args ...interface{})
|
logf func(fmt string, args ...any)
|
||||||
linkMon *monitor.Mon // may be nil
|
linkMon *monitor.Mon // may be nil
|
||||||
nativeTun *tun.NativeTun
|
nativeTun *tun.NativeTun
|
||||||
routeChangeCallback *winipcfg.RouteChangeCallback
|
routeChangeCallback *winipcfg.RouteChangeCallback
|
||||||
|
@ -44,8 +44,8 @@ func NewWatchdog(e Engine) Engine {
|
|||||||
|
|
||||||
type watchdogEngine struct {
|
type watchdogEngine struct {
|
||||||
wrap Engine
|
wrap Engine
|
||||||
logf func(format string, args ...interface{})
|
logf func(format string, args ...any)
|
||||||
fatalf func(format string, args ...interface{})
|
fatalf func(format string, args ...any)
|
||||||
maxWait time.Duration
|
maxWait time.Duration
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,7 +57,7 @@ func TestWatchdog(t *testing.T) {
|
|||||||
logBuf := new(tstest.MemLogger)
|
logBuf := new(tstest.MemLogger)
|
||||||
fatalCalled := make(chan struct{})
|
fatalCalled := make(chan struct{})
|
||||||
wdEngine.logf = logBuf.Logf
|
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...))
|
t.Logf("FATAL: %s", fmt.Sprintf(format, args...))
|
||||||
fatalCalled <- struct{}{}
|
fatalCalled <- struct{}{}
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,7 @@ func noError(t *testing.T, err error) bool {
|
|||||||
return false
|
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) {
|
if reflect.DeepEqual(expected, actual) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
@ -37,7 +37,7 @@ type strCache struct {
|
|||||||
// and rewrites peer keys from wireguard-go into Tailscale format.
|
// and rewrites peer keys from wireguard-go into Tailscale format.
|
||||||
func NewLogger(logf logger.Logf) *Logger {
|
func NewLogger(logf logger.Logf) *Logger {
|
||||||
ret := new(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") {
|
if strings.Contains(format, "Routine:") && !strings.Contains(format, "receive incoming") {
|
||||||
// wireguard-go logs as it starts and stops routines.
|
// wireguard-go logs as it starts and stops routines.
|
||||||
// Drop those; there are a lot of them, and they're just noise.
|
// 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.
|
// 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.
|
// 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)
|
copy(newargs, args)
|
||||||
for i, arg := range newargs {
|
for i, arg := range newargs {
|
||||||
// We want to replace *device.Peer args with the Tailscale-formatted version of themselves.
|
// We want to replace *device.Peer args with the Tailscale-formatted version of themselves.
|
||||||
|
@ -18,22 +18,22 @@ import (
|
|||||||
func TestLogger(t *testing.T) {
|
func TestLogger(t *testing.T) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
format string
|
format string
|
||||||
args []interface{}
|
args []any
|
||||||
want string
|
want string
|
||||||
omit bool
|
omit bool
|
||||||
}{
|
}{
|
||||||
{"hi", nil, "hi", false},
|
{"hi", nil, "hi", false},
|
||||||
{"Routine: starting", nil, "", true},
|
{"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 {
|
type log struct {
|
||||||
format string
|
format string
|
||||||
args []interface{}
|
args []any
|
||||||
}
|
}
|
||||||
|
|
||||||
c := make(chan log, 1)
|
c := make(chan log, 1)
|
||||||
logf := func(format string, args ...interface{}) {
|
logf := func(format string, args ...any) {
|
||||||
select {
|
select {
|
||||||
case c <- log{format, args}:
|
case c <- log{format, args}:
|
||||||
default:
|
default:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user