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
@@ -258,7 +258,7 @@ func TestLinuxDNSMode(t *testing.T) {
}
}
type memFS map[string]interface{} // full path => string for regular files
type memFS map[string]any // full path => string for regular files
func (m memFS) Stat(name string) (isRegular bool, err error) {
v, ok := m[name]
+2 -2
View File
@@ -140,12 +140,12 @@ func (m *nmManager) trySet(ctx context.Context, config OSConfig) error {
// NetworkManager wipes out IPv6 address configuration unless we
// tell it explicitly to keep it. Read out the current interface
// settings and mirror them out to NetworkManager.
var addrs6 []map[string]interface{}
var addrs6 []map[string]any
addrs, _, err := interfaces.Tailscale()
if err == nil {
for _, a := range addrs {
if a.Is6() {
addrs6 = append(addrs6, map[string]interface{}{
addrs6 = append(addrs6, map[string]any{
"address": a.String(),
"prefix": uint32(128),
})
+1 -1
View File
@@ -141,7 +141,7 @@ func (m *resolvedManager) resync(ctx context.Context, signals chan *dbus.Signal)
if signal.Path != dbusPath || signal.Name != dbusInterface+"."+dbusOwnerSignal {
continue
}
// signal.Body is a []interface{} of 3 strings: bus name, previous owner, new owner.
// signal.Body is a []any of 3 strings: bus name, previous owner, new owner.
if len(signal.Body) != 3 {
m.logf("[unexpectected] DBus NameOwnerChanged len(Body) = %d, want 3")
}
+1 -1
View File
@@ -711,7 +711,7 @@ type response struct {
}
var dnsParserPool = &sync.Pool{
New: func() interface{} {
New: func() any {
return new(dnsParser)
},
}
+2 -2
View File
@@ -221,7 +221,7 @@ func weirdoGoCNAMEHandler(target string) dns.HandlerFunc {
// provided.
//
// Types supported: netaddr.IP.
func dnsHandler(answers ...interface{}) dns.HandlerFunc {
func dnsHandler(answers ...any) dns.HandlerFunc {
return func(w dns.ResponseWriter, req *dns.Msg) {
m := new(dns.Msg)
m.SetReply(req)
@@ -303,7 +303,7 @@ func dnsHandler(answers ...interface{}) dns.HandlerFunc {
}
}
func serveDNS(tb testing.TB, addr string, records ...interface{}) *dns.Server {
func serveDNS(tb testing.TB, addr string, records ...any) *dns.Server {
if len(records)%2 != 0 {
panic("must have an even number of record values")
}
+2 -2
View File
@@ -454,7 +454,7 @@ func TestDelegate(t *testing.T) {
// intend to handle responses this large, so there should be truncation.
hugeTXT := generateTXT(64000, randSource)
records := []interface{}{
records := []any{
"test.site.",
resolveToIP(testipv4, testipv6, "dns.test.site."),
"LCtesT.SiTe.",
@@ -1105,7 +1105,7 @@ func TestHandleExitNodeDNSQueryWithNetPkg(t *testing.T) {
t.Skip("skipping test on Windows; waiting for golang.org/issue/33097")
}
records := []interface{}{
records := []any{
"no-records.test.",
dnsHandler(),
+1 -1
View File
@@ -129,7 +129,7 @@ func (r *Resolver) LookupIP(ctx context.Context, host string) (ip, v6 net.IP, al
ip, ip6 net.IP
allIPs []net.IPAddr
}
ch := r.sf.DoChan(host, func() (interface{}, error) {
ch := r.sf.DoChan(host, func() (any, error) {
ip, ip6, allIPs, err := r.lookupIP(host)
if err != nil {
return nil, err
+1 -1
View File
@@ -103,7 +103,7 @@ type msgResource struct {
var ErrCacheMiss = errors.New("cache miss")
var parserPool = &sync.Pool{
New: func() interface{} { return new(dnsmessage.Parser) },
New: func() any { return new(dnsmessage.Parser) },
}
// ReplyFromCache writes a DNS reply to w for the provided DNS query message,
+3 -3
View File
@@ -118,17 +118,17 @@ type responseOpt bool
type ttlOpt uint32
func makeQ(txID uint16, name string, opt ...interface{}) []byte {
func makeQ(txID uint16, name string, opt ...any) []byte {
opt = append(opt, responseOpt(false))
return makeDNSPkt(txID, name, opt...)
}
func makeRes(txID uint16, name string, opt ...interface{}) []byte {
func makeRes(txID uint16, name string, opt ...any) []byte {
opt = append(opt, responseOpt(true))
return makeDNSPkt(txID, name, opt...)
}
func makeDNSPkt(txID uint16, name string, opt ...interface{}) []byte {
func makeDNSPkt(txID uint16, name string, opt ...any) []byte {
typ := dnsmessage.TypeA
class := dnsmessage.ClassINET
var response bool
+3 -3
View File
@@ -46,7 +46,7 @@ type Cache struct {
// entry is the container/list element type.
type entry struct {
key Tuple
value interface{}
value any
}
// Add adds a value to the cache, set or updating its associated
@@ -54,7 +54,7 @@ type entry struct {
//
// If MaxEntries is non-zero and the length of the cache is greater
// after any addition, the least recently used value is evicted.
func (c *Cache) Add(key Tuple, value interface{}) {
func (c *Cache) Add(key Tuple, value any) {
if c.m == nil {
c.m = make(map[Tuple]*list.Element)
c.ll = list.New()
@@ -73,7 +73,7 @@ func (c *Cache) Add(key Tuple, value interface{}) {
// Get looks up a key's value from the cache, also reporting
// whether it was present.
func (c *Cache) Get(key Tuple) (value interface{}, ok bool) {
func (c *Cache) Get(key Tuple) (value any, ok bool) {
if ele, hit := c.m[key]; hit {
c.ll.MoveToFront(ele)
return ele.Value.(*entry).value, true
+1 -1
View File
@@ -25,7 +25,7 @@ func TestCache(t *testing.T) {
t.Fatalf("Len = %d; want %d", got, want)
}
}
wantVal := func(key Tuple, want interface{}) {
wantVal := func(key Tuple, want any) {
t.Helper()
got, ok := c.Get(key)
if !ok {
+2 -2
View File
@@ -191,7 +191,7 @@ func (c *Client) enoughRegions() int {
return 3
}
func (c *Client) logf(format string, a ...interface{}) {
func (c *Client) logf(format string, a ...any) {
if c.Logf != nil {
c.Logf(format, a...)
} else {
@@ -199,7 +199,7 @@ func (c *Client) logf(format string, a ...interface{}) {
}
}
func (c *Client) vlogf(format string, a ...interface{}) {
func (c *Client) vlogf(format string, a ...any) {
if c.Verbose || debugNetcheck {
c.logf(format, a...)
}
+2 -2
View File
@@ -119,7 +119,7 @@ func TestWorksWhenUDPBlocked(t *testing.T) {
func TestAddReportHistoryAndSetPreferredDERP(t *testing.T) {
// report returns a *Report from (DERP host, time.Duration)+ pairs.
report := func(a ...interface{}) *Report {
report := func(a ...any) *Report {
r := &Report{RegionLatency: map[int]time.Duration{}}
for i := 0; i < len(a); i += 2 {
s := a[i].(string)
@@ -606,7 +606,7 @@ func TestLogConciseReport(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
var buf bytes.Buffer
c := &Client{Logf: func(f string, a ...interface{}) { fmt.Fprintf(&buf, f, a...) }}
c := &Client{Logf: func(f string, a ...any) { fmt.Fprintf(&buf, f, a...) }}
c.logConciseReport(tt.r, dm)
if got := strings.TrimPrefix(buf.String(), "[v1] report: "); got != tt.want {
t.Errorf("unexpected result.\n got: %#q\nwant: %#q\n", got, tt.want)
+1 -1
View File
@@ -15,7 +15,7 @@ import (
"inet.af/netaddr"
)
type upnpClient interface{}
type upnpClient any
type uPnPDiscoResponse struct{}
+1 -1
View File
@@ -67,7 +67,7 @@ func NewTestIGD(logf logger.Logf, t TestIGDOptions) (*TestIGD, error) {
doPCP: t.PCP,
doUPnP: t.UPnP,
}
d.logf = func(msg string, args ...interface{}) {
d.logf = func(msg string, args ...any) {
// Don't log after the device has closed;
// stray trailing logging angers testing.T.Logf.
if d.closed.Get() {
+1 -1
View File
@@ -95,7 +95,7 @@ func (s *Server) dial(ctx context.Context, network, addr string) (net.Conn, erro
return dial(ctx, network, addr)
}
func (s *Server) logf(format string, args ...interface{}) {
func (s *Server) logf(format string, args ...any) {
logf := s.Logf
if logf == nil {
logf = log.Printf
+1 -1
View File
@@ -60,7 +60,7 @@ var (
// parsedPacketPool holds a pool of Parsed structs for use in filtering.
// This is needed because escape analysis cannot see that parsed packets
// do not escape through {Pre,Post}Filter{In,Out}.
var parsedPacketPool = sync.Pool{New: func() interface{} { return new(packet.Parsed) }}
var parsedPacketPool = sync.Pool{New: func() any { return new(packet.Parsed) }}
// FilterFunc is a packet-filtering function with access to the Wrapper device.
// It must not hold onto the packet struct, as its backing storage will be reused.