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:
Josh Bleecher Snyder
2022-03-16 16:27:57 -07:00
committed by Josh Bleecher Snyder
parent 5f176f24db
commit 0868329936
88 changed files with 204 additions and 204 deletions
+1 -1
View File
@@ -432,7 +432,7 @@ func TestLoggingPrivacy(t *testing.T) {
logged bool
testLogger logger.Logf
)
logf := func(format string, args ...interface{}) {
logf := func(format string, args ...any) {
testLogger(format, args...)
logged = true
}
+1 -1
View File
@@ -1197,7 +1197,7 @@ var errDropDerpPacket = errors.New("too many DERP packets queued; dropping")
var errNoUDP = errors.New("no UDP available on platform")
var udpAddrPool = &sync.Pool{
New: func() interface{} { return new(net.UDPAddr) },
New: func() any { return new(net.UDPAddr) },
}
// sendUDP sends UDP packet b to ipp.
+2 -2
View File
@@ -543,7 +543,7 @@ func makeNestable(t *testing.T) (logf logger.Logf, setT func(t *testing.T)) {
mu.Unlock()
}
logf = func(s string, args ...interface{}) {
logf = func(s string, args ...any) {
mu.RLock()
t := cur
@@ -922,7 +922,7 @@ func testActiveDiscovery(t *testing.T, d *devices) {
setT(t)
start := time.Now()
wlogf := func(msg string, args ...interface{}) {
wlogf := func(msg string, args ...any) {
t.Helper()
msg = fmt.Sprintf("%s: %s", time.Since(start).Truncate(time.Microsecond), msg)
tlogf(msg, args...)
+1 -1
View File
@@ -340,7 +340,7 @@ func (m *Mon) debounce() {
}
}
func jsonSummary(x interface{}) interface{} {
func jsonSummary(x any) any {
j, err := json.Marshal(x)
if err != nil {
return err
+1 -1
View File
@@ -178,7 +178,7 @@ func ipOfAddr(a route.Addr) netaddr.IP {
return netaddr.IP{}
}
func fmtAddr(a route.Addr) interface{} {
func fmtAddr(a route.Addr) any {
if a == nil {
return nil
}
+1 -1
View File
@@ -21,7 +21,7 @@ import (
func TestInjectInboundLeak(t *testing.T) {
tunDev := tstun.NewFake()
dialer := new(tsdial.Dialer)
logf := func(format string, args ...interface{}) {
logf := func(format string, args ...any) {
if !t.Failed() {
t.Logf(format, args...)
}
+1 -1
View File
@@ -84,7 +84,7 @@ type netfilterRunner interface {
type linuxRouter struct {
closed syncs.AtomicBool
logf func(fmt string, args ...interface{})
logf func(fmt string, args ...any)
tunname string
linkMon *monitor.Mon
unregLinkMon func()
+1 -1
View File
@@ -28,7 +28,7 @@ import (
)
type winRouter struct {
logf func(fmt string, args ...interface{})
logf func(fmt string, args ...any)
linkMon *monitor.Mon // may be nil
nativeTun *tun.NativeTun
routeChangeCallback *winipcfg.RouteChangeCallback
+2 -2
View File
@@ -44,8 +44,8 @@ func NewWatchdog(e Engine) Engine {
type watchdogEngine struct {
wrap Engine
logf func(format string, args ...interface{})
fatalf func(format string, args ...interface{})
logf func(format string, args ...any)
fatalf func(format string, args ...any)
maxWait time.Duration
}
+1 -1
View File
@@ -57,7 +57,7 @@ func TestWatchdog(t *testing.T) {
logBuf := new(tstest.MemLogger)
fatalCalled := make(chan struct{})
wdEngine.logf = logBuf.Logf
wdEngine.fatalf = func(format string, args ...interface{}) {
wdEngine.fatalf = func(format string, args ...any) {
t.Logf("FATAL: %s", fmt.Sprintf(format, args...))
fatalCalled <- struct{}{}
}
+1 -1
View File
@@ -25,7 +25,7 @@ func noError(t *testing.T, err error) bool {
return false
}
func equal(t *testing.T, expected, actual interface{}) bool {
func equal(t *testing.T, expected, actual any) bool {
if reflect.DeepEqual(expected, actual) {
return true
}
+2 -2
View File
@@ -37,7 +37,7 @@ type strCache struct {
// and rewrites peer keys from wireguard-go into Tailscale format.
func NewLogger(logf logger.Logf) *Logger {
ret := new(Logger)
wrapper := func(format string, args ...interface{}) {
wrapper := func(format string, args ...any) {
if strings.Contains(format, "Routine:") && !strings.Contains(format, "receive incoming") {
// wireguard-go logs as it starts and stops routines.
// Drop those; there are a lot of them, and they're just noise.
@@ -60,7 +60,7 @@ func NewLogger(logf logger.Logf) *Logger {
}
// Duplicate the args slice so that we can modify it.
// This is not always required, but the code required to avoid it is not worth the complexity.
newargs := make([]interface{}, len(args))
newargs := make([]any, len(args))
copy(newargs, args)
for i, arg := range newargs {
// We want to replace *device.Peer args with the Tailscale-formatted version of themselves.
+4 -4
View File
@@ -18,22 +18,22 @@ import (
func TestLogger(t *testing.T) {
tests := []struct {
format string
args []interface{}
args []any
want string
omit bool
}{
{"hi", nil, "hi", false},
{"Routine: starting", nil, "", true},
{"%v says it misses you", []interface{}{stringer("peer(IMTB…r7lM)")}, "[IMTBr] says it misses you", false},
{"%v says it misses you", []any{stringer("peer(IMTB…r7lM)")}, "[IMTBr] says it misses you", false},
}
type log struct {
format string
args []interface{}
args []any
}
c := make(chan log, 1)
logf := func(format string, args ...interface{}) {
logf := func(format string, args ...any) {
select {
case c <- log{format, args}:
default: