From d8aa09e04c4e38155dfcee6ed0495c2b29f604fc Mon Sep 17 00:00:00 2001 From: Kevin Krakauer Date: Tue, 8 Nov 2022 13:12:12 -0800 Subject: [PATCH] convert uses of interface{} to any Done via: find . -name "*.go" | xargs sed -i -E 's/interface\{\}/any/g' PiperOrigin-RevId: 487033228 --- go.mod | 2 +- pkg/abi/linux/netfilter_test.go | 2 +- pkg/binary/binary.go | 6 +-- pkg/binary/binary_test.go | 14 +++--- pkg/bufferv2/chunk.go | 2 +- pkg/bufferv2/view.go | 2 +- pkg/compressio/compressio.go | 4 +- pkg/compressio/compressio_test.go | 6 +-- pkg/context/context.go | 8 +-- pkg/control/server/server.go | 2 +- pkg/coverage/coverage.go | 2 +- pkg/cpuid/cpuid.go | 2 +- pkg/lisafs/message.go | 2 +- pkg/log/glog.go | 2 +- pkg/log/json.go | 2 +- pkg/log/json_k8s.go | 2 +- pkg/log/log.go | 46 ++++++++--------- pkg/log/rate_limited.go | 6 +-- pkg/metric/metric.go | 4 +- pkg/metric/metric_test.go | 2 +- pkg/p9/client.go | 2 +- pkg/p9/p9test/p9test.go | 2 +- pkg/p9/transport.go | 2 +- pkg/refs/refcounter.go | 4 +- pkg/refs/refcounter_state.go | 2 +- pkg/refsvfs2/refs_template.go | 2 +- pkg/ring0/kernel_unsafe.go | 2 +- pkg/seccomp/seccomp_rules.go | 4 +- pkg/segment/set.go | 4 +- pkg/sentry/contexttest/contexttest.go | 10 ++-- pkg/sentry/fs/context.go | 2 +- pkg/sentry/fs/copy_up.go | 2 +- pkg/sentry/fs/dev/fs.go | 2 +- pkg/sentry/fs/fdpipe/pipe_test.go | 2 +- pkg/sentry/fs/file_overlay_test.go | 2 +- pkg/sentry/fs/filesystems.go | 2 +- pkg/sentry/fs/gofer/fs.go | 2 +- pkg/sentry/fs/gofer/inode_state.go | 2 +- pkg/sentry/fs/host/host.go | 2 +- pkg/sentry/fs/lock/lock.go | 2 +- pkg/sentry/fs/mount_overlay.go | 2 +- pkg/sentry/fs/proc/fs.go | 2 +- pkg/sentry/fs/proc/net.go | 4 +- pkg/sentry/fs/proc/seqfile/seqfile.go | 2 +- pkg/sentry/fs/restore.go | 2 +- pkg/sentry/fs/sys/fs.go | 2 +- pkg/sentry/fs/tmpfs/fs.go | 2 +- pkg/sentry/fs/tty/fs.go | 2 +- pkg/sentry/fsimpl/devtmpfs/devtmpfs.go | 2 +- pkg/sentry/fsimpl/gofer/filesystem.go | 6 +-- pkg/sentry/fsimpl/gofer/handle.go | 2 +- pkg/sentry/fsimpl/gofer/regular_file.go | 2 +- pkg/sentry/fsimpl/gofer/revalidate.go | 2 +- pkg/sentry/fsimpl/overlay/filesystem.go | 2 +- pkg/sentry/fsimpl/proc/task_net.go | 4 +- pkg/sentry/fsimpl/tmpfs/regular_file.go | 2 +- pkg/sentry/fsimpl/tmpfs/tmpfs.go | 4 +- pkg/sentry/hostfd/hostfd.go | 2 +- pkg/sentry/inet/inet.go | 2 +- pkg/sentry/inet/test_stack.go | 2 +- pkg/sentry/kernel/auth/context.go | 2 +- pkg/sentry/kernel/kcov.go | 2 +- pkg/sentry/kernel/kernel.go | 4 +- pkg/sentry/kernel/syscalls.go | 4 +- pkg/sentry/kernel/task_context.go | 6 +-- pkg/sentry/kernel/task_image.go | 2 +- pkg/sentry/kernel/task_log.go | 6 +-- pkg/sentry/kernel/task_syscall.go | 2 +- pkg/sentry/loader/vdso.go | 2 +- pkg/sentry/mm/address_space.go | 2 +- pkg/sentry/mm/aio_context.go | 6 +-- pkg/sentry/platform/kvm/kvm.go | 2 +- pkg/sentry/platform/kvm/kvm_test.go | 4 +- pkg/sentry/platform/kvm/testutil/testutil.go | 2 +- pkg/sentry/platform/platform.go | 2 +- pkg/sentry/platform/ptrace/ptrace.go | 2 +- pkg/sentry/seccheck/config.go | 2 +- pkg/sentry/seccheck/metadata.go | 4 +- pkg/sentry/seccheck/sinks/null/null.go | 2 +- pkg/sentry/seccheck/sinks/remote/remote.go | 6 +-- .../seccheck/sinks/remote/remote_test.go | 14 +++--- pkg/sentry/socket/control/control.go | 6 +-- pkg/sentry/socket/hostinet/stack.go | 4 +- pkg/sentry/socket/netfilter/netfilter.go | 2 +- pkg/sentry/socket/netstack/stack.go | 2 +- pkg/sentry/socket/unix/transport/unix.go | 2 +- pkg/sentry/strace/strace.go | 4 +- pkg/sentry/syscalls/linux/sys_aio.go | 4 +- pkg/sentry/syscalls/linux/sys_file.go | 2 +- pkg/sentry/syscalls/linux/vfs2/getdents.go | 2 +- pkg/sentry/time/calibrated_clock.go | 16 +++--- pkg/sentry/vfs/context.go | 4 +- pkg/sentry/vfs/filesystem_type.go | 2 +- pkg/sentry/vfs/pathname.go | 2 +- pkg/sentry/vfs/resolving_path.go | 2 +- pkg/sentry/watchdog/watchdog.go | 2 +- pkg/shim/epoll.go | 2 +- pkg/shim/oom_v2.go | 2 +- pkg/shim/proc/io.go | 2 +- pkg/shim/runsc/utils.go | 2 +- pkg/shim/service.go | 12 ++--- pkg/state/state.go | 20 ++++---- pkg/state/tests/array.go | 8 +-- pkg/state/tests/array_test.go | 22 ++++---- pkg/state/tests/bench_test.go | 18 +++---- pkg/state/tests/float_test.go | 16 +++--- pkg/state/tests/integer_test.go | 8 +-- pkg/state/tests/load.go | 2 +- pkg/state/tests/load_test.go | 20 ++++---- pkg/state/tests/map.go | 4 +- pkg/state/tests/map_test.go | 16 +++--- pkg/state/tests/struct.go | 10 ++-- pkg/state/tests/struct_test.go | 16 +++--- pkg/state/tests/tests.go | 24 ++++----- pkg/state/types.go | 2 +- pkg/sync/checklocks_on_unsafe.go | 2 +- pkg/sync/runtime_unsafe.go | 2 +- pkg/syncevent/waiter_test.go | 4 +- pkg/syncevent/waiter_unsafe.go | 2 +- pkg/tcpip/faketime/faketime.go | 4 +- pkg/tcpip/socketops.go | 2 +- pkg/tcpip/stack/packet_buffer.go | 2 +- pkg/tcpip/stack/stack.go | 2 +- pkg/tcpip/stack/stack_options.go | 4 +- pkg/tcpip/transport/tcp/connect.go | 2 +- pkg/tcpip/transport/tcp/segment.go | 2 +- pkg/tcpip/transport/tcp/segment_heap.go | 4 +- pkg/test/dockerutil/dockerutil.go | 12 ++--- pkg/test/testutil/sh.go | 2 +- pkg/test/testutil/testutil.go | 6 +-- pkg/trie/trie.go | 8 +-- pkg/trie/trie_test.go | 4 +- pkg/urpc/urpc.go | 20 ++++---- runsc/boot/vfs.go | 2 +- runsc/cgroup/cgroup.go | 2 +- runsc/cgroup/systemd.go | 4 +- runsc/cgroup/systemd_test.go | 2 +- runsc/cmd/boot.go | 2 +- runsc/cmd/checkpoint.go | 2 +- runsc/cmd/cmd.go | 2 +- runsc/cmd/create.go | 2 +- runsc/cmd/debug.go | 2 +- runsc/cmd/delete.go | 2 +- runsc/cmd/do.go | 6 +-- runsc/cmd/events.go | 2 +- runsc/cmd/exec.go | 6 +-- runsc/cmd/gofer.go | 2 +- runsc/cmd/help.go | 2 +- runsc/cmd/install.go | 26 +++++----- runsc/cmd/install_test.go | 24 ++++----- runsc/cmd/kill.go | 2 +- runsc/cmd/list.go | 2 +- runsc/cmd/mitigate.go | 2 +- runsc/cmd/pause.go | 2 +- runsc/cmd/platforms.go | 2 +- runsc/cmd/ps.go | 2 +- runsc/cmd/read_control.go | 2 +- runsc/cmd/restore.go | 2 +- runsc/cmd/resume.go | 2 +- runsc/cmd/run.go | 2 +- runsc/cmd/spec.go | 2 +- runsc/cmd/start.go | 2 +- runsc/cmd/state.go | 2 +- runsc/cmd/statefile.go | 2 +- runsc/cmd/symbolize.go | 2 +- runsc/cmd/syscalls.go | 2 +- runsc/cmd/trace/create.go | 2 +- runsc/cmd/trace/create_test.go | 2 +- runsc/cmd/trace/delete.go | 2 +- runsc/cmd/trace/list.go | 2 +- runsc/cmd/trace/metadata.go | 2 +- runsc/cmd/trace/procfs.go | 2 +- runsc/cmd/trace/trace.go | 2 +- runsc/cmd/usage.go | 2 +- runsc/cmd/util/util.go | 6 +-- runsc/cmd/wait.go | 2 +- runsc/cmd/write_control.go | 2 +- runsc/config/config.go | 10 ++-- runsc/container/state_file.go | 4 +- runsc/container/trace_test.go | 2 +- runsc/flag/flag.go | 2 +- runsc/specutils/namespace.go | 2 +- test/benchmarks/harness/util.go | 2 +- test/cmd/test_app/fds.go | 4 +- test/cmd/test_app/main.go | 14 +++--- test/iptables/nat.go | 6 +-- test/packetimpact/testbench/layers.go | 4 +- test/root/crictl_test.go | 12 ++--- test/runner/main.go | 2 +- test/runtimes/runner/lib/lib.go | 4 +- test/trace/trace_test.go | 2 +- tools/bigquery/bigquery.go | 2 +- tools/checkaligned/checkaligned.go | 2 +- tools/checkescape/checkescape.go | 4 +- tools/checkinfo/checkinfo.go | 2 +- tools/checklinkname/check_linkname.go | 2 +- tools/checklocks/annotations.go | 2 +- tools/checklocks/checklocks.go | 2 +- tools/checklocks/facts.go | 10 ++-- tools/checkunsafe/check_unsafe.go | 2 +- tools/go_generics/go_merge/main.go | 2 +- tools/go_generics/tests/all_stmts/input.go | 2 +- tools/go_generics/tests/all_stmts/output.go | 2 +- tools/go_marshal/analysis/analysis_unsafe.go | 2 +- tools/go_marshal/gomarshal/util.go | 10 ++-- tools/go_marshal/test/marshal_test.go | 50 +++++++++---------- tools/go_stateify/main.go | 2 +- tools/nogo/check/analyzers.go | 2 +- tools/nogo/check/check.go | 4 +- tools/nogo/cli/cli.go | 12 ++--- tools/nogo/facts/facts.go | 6 +-- tools/nogo/flags/flags.go | 4 +- tools/parsers/parser_main.go | 2 +- tools/tracereplay/main/main.go | 4 +- tools/xdp/drop.go | 2 +- tools/xdp/pass.go | 2 +- tools/xdp/tcpdump.go | 2 +- tools/yamltest/main.go | 10 ++-- webhook/pkg/injector/webhook.go | 4 +- website/cmd/syscalldocs/main.go | 2 +- 220 files changed, 509 insertions(+), 509 deletions(-) diff --git a/go.mod b/go.mod index 1b8865e74..066dd7ed3 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module gvisor.dev/gvisor -go 1.17 +go 1.18 require ( github.com/BurntSushi/toml v0.3.1 diff --git a/pkg/abi/linux/netfilter_test.go b/pkg/abi/linux/netfilter_test.go index 600820a0b..e854a88f1 100644 --- a/pkg/abi/linux/netfilter_test.go +++ b/pkg/abi/linux/netfilter_test.go @@ -21,7 +21,7 @@ import ( func TestSizes(t *testing.T) { testCases := []struct { - typ interface{} + typ any defined uintptr }{ {IPTEntry{}, SizeOfIPTEntry}, diff --git a/pkg/binary/binary.go b/pkg/binary/binary.go index 25065aef9..28b6ff6c1 100644 --- a/pkg/binary/binary.go +++ b/pkg/binary/binary.go @@ -59,7 +59,7 @@ func AppendUint64(buf []byte, order binary.ByteOrder, num uint64) []byte { // data must only contain fixed-length signed and unsigned ints, arrays, // slices, structs and compositions of said types. data may be a pointer, // but cannot contain pointers. -func Marshal(buf []byte, order binary.ByteOrder, data interface{}) []byte { +func Marshal(buf []byte, order binary.ByteOrder, data any) []byte { return marshal(buf, order, reflect.Indirect(reflect.ValueOf(data))) } @@ -104,7 +104,7 @@ func marshal(buf []byte, order binary.ByteOrder, data reflect.Value) []byte { // data must be a slice or a pointer and buf must have a length of exactly // Size(data). data must only contain fixed-length signed and unsigned ints, // arrays, slices, structs and compositions of said types. -func Unmarshal(buf []byte, order binary.ByteOrder, data interface{}) { +func Unmarshal(buf []byte, order binary.ByteOrder, data any) { value := reflect.ValueOf(data) switch value.Kind() { case reflect.Ptr: @@ -170,7 +170,7 @@ func unmarshal(buf []byte, order binary.ByteOrder, data reflect.Value) []byte { // Size calculates the buffer sized needed by Marshal or Unmarshal. // // Size only support the types supported by Marshal. -func Size(v interface{}) uintptr { +func Size(v any) uintptr { return sizeof(reflect.Indirect(reflect.ValueOf(v))) } diff --git a/pkg/binary/binary_test.go b/pkg/binary/binary_test.go index 4d609a438..9e9abff9c 100644 --- a/pkg/binary/binary_test.go +++ b/pkg/binary/binary_test.go @@ -38,18 +38,18 @@ func TestSize(t *testing.T) { func TestPanic(t *testing.T) { tests := []struct { name string - f func([]byte, binary.ByteOrder, interface{}) - data interface{} + f func([]byte, binary.ByteOrder, any) + data any want string }{ {"Unmarshal int", Unmarshal, 5, "invalid type: int"}, {"Unmarshal []int", Unmarshal, []int{5}, "invalid type: int"}, - {"Marshal int", func(_ []byte, bo binary.ByteOrder, d interface{}) { Marshal(nil, bo, d) }, 5, "invalid type: int"}, - {"Marshal int[]", func(_ []byte, bo binary.ByteOrder, d interface{}) { Marshal(nil, bo, d) }, []int{5}, "invalid type: int"}, + {"Marshal int", func(_ []byte, bo binary.ByteOrder, d any) { Marshal(nil, bo, d) }, 5, "invalid type: int"}, + {"Marshal int[]", func(_ []byte, bo binary.ByteOrder, d any) { Marshal(nil, bo, d) }, []int{5}, "invalid type: int"}, {"Unmarshal short buffer", Unmarshal, newInt32(5), "runtime error: index out of range"}, - {"Unmarshal long buffer", func(_ []byte, bo binary.ByteOrder, d interface{}) { Unmarshal(make([]byte, 50), bo, d) }, newInt32(5), "buffer too long by 46 bytes"}, - {"marshal int", func(_ []byte, bo binary.ByteOrder, d interface{}) { marshal(nil, bo, reflect.ValueOf(d)) }, 5, "invalid type: int"}, - {"Size int", func(_ []byte, _ binary.ByteOrder, d interface{}) { Size(d) }, 5, "invalid type: int"}, + {"Unmarshal long buffer", func(_ []byte, bo binary.ByteOrder, d any) { Unmarshal(make([]byte, 50), bo, d) }, newInt32(5), "buffer too long by 46 bytes"}, + {"marshal int", func(_ []byte, bo binary.ByteOrder, d any) { marshal(nil, bo, reflect.ValueOf(d)) }, 5, "invalid type: int"}, + {"Size int", func(_ []byte, _ binary.ByteOrder, d any) { Size(d) }, 5, "invalid type: int"}, } for _, test := range tests { diff --git a/pkg/bufferv2/chunk.go b/pkg/bufferv2/chunk.go index 4c62216ea..09c94da56 100644 --- a/pkg/bufferv2/chunk.go +++ b/pkg/bufferv2/chunk.go @@ -53,7 +53,7 @@ var chunkPools [numPools]sync.Pool func init() { for i := 0; i < numPools; i++ { chunkSize := baseChunkSize * (1 << i) - chunkPools[i].New = func() interface{} { + chunkPools[i].New = func() any { return &chunk{ data: make([]byte, chunkSize), } diff --git a/pkg/bufferv2/view.go b/pkg/bufferv2/view.go index 20811497f..8e45f220e 100644 --- a/pkg/bufferv2/view.go +++ b/pkg/bufferv2/view.go @@ -26,7 +26,7 @@ import ( const ReadSize = 512 var viewPool = sync.Pool{ - New: func() interface{} { + New: func() any { return &View{} }, } diff --git a/pkg/compressio/compressio.go b/pkg/compressio/compressio.go index b6cfeb377..9801160d0 100644 --- a/pkg/compressio/compressio.go +++ b/pkg/compressio/compressio.go @@ -58,13 +58,13 @@ import ( ) var bufPool = sync.Pool{ - New: func() interface{} { + New: func() any { return bytes.NewBuffer(nil) }, } var chunkPool = sync.Pool{ - New: func() interface{} { + New: func() any { return new(chunk) }, } diff --git a/pkg/compressio/compressio_test.go b/pkg/compressio/compressio_test.go index 86dc47e44..830e148f8 100644 --- a/pkg/compressio/compressio_test.go +++ b/pkg/compressio/compressio_test.go @@ -27,9 +27,9 @@ import ( ) type harness interface { - Errorf(format string, v ...interface{}) - Fatalf(format string, v ...interface{}) - Logf(format string, v ...interface{}) + Errorf(format string, v ...any) + Fatalf(format string, v ...any) + Logf(format string, v ...any) } func initTest(t harness, size int) []byte { diff --git a/pkg/context/context.go b/pkg/context/context.go index c68a4ffc3..469e254ca 100644 --- a/pkg/context/context.go +++ b/pkg/context/context.go @@ -186,7 +186,7 @@ func Background() Context { // WithValue returns a copy of parent in which the value associated with key is // val. -func WithValue(parent Context, key, val interface{}) Context { +func WithValue(parent Context, key, val any) Context { return &withValue{ Context: parent, key: key, @@ -196,12 +196,12 @@ func WithValue(parent Context, key, val interface{}) Context { type withValue struct { Context - key interface{} - val interface{} + key any + val any } // Value implements Context.Value. -func (ctx *withValue) Value(key interface{}) interface{} { +func (ctx *withValue) Value(key any) any { if key == ctx.key { return ctx.val } diff --git a/pkg/control/server/server.go b/pkg/control/server/server.go index 889568177..ec6bb618f 100644 --- a/pkg/control/server/server.go +++ b/pkg/control/server/server.go @@ -124,7 +124,7 @@ func (s *Server) serve() { } // Register registers a specific control interface with the server. -func (s *Server) Register(obj interface{}) { +func (s *Server) Register(obj any) { s.server.Register(obj) } diff --git a/pkg/coverage/coverage.go b/pkg/coverage/coverage.go index 79238ad51..05fb90054 100644 --- a/pkg/coverage/coverage.go +++ b/pkg/coverage/coverage.go @@ -113,7 +113,7 @@ func ClearCoverageData() { } var coveragePool = sync.Pool{ - New: func() interface{} { + New: func() any { return make([]byte, 0) }, } diff --git a/pkg/cpuid/cpuid.go b/pkg/cpuid/cpuid.go index 6da806643..585a9a7d2 100644 --- a/pkg/cpuid/cpuid.go +++ b/pkg/cpuid/cpuid.go @@ -42,7 +42,7 @@ const ( // context represents context.Context. type context interface { - Value(key interface{}) interface{} + Value(key any) any } // FromContext returns the FeatureSet from the context, if available. diff --git a/pkg/lisafs/message.go b/pkg/lisafs/message.go index 41e2f804a..06923788b 100644 --- a/pkg/lisafs/message.go +++ b/pkg/lisafs/message.go @@ -52,7 +52,7 @@ import ( // // String() implementations must ensure that the message struct doesn't escape. // For instance, directly passing the struct to fmt.Sprintf() escapes it -// because of the implicit conversion to interface{}. +// because of the implicit conversion to any. type marshalFunc func([]byte) []byte type unmarshalFunc func([]byte) ([]byte, bool) diff --git a/pkg/log/glog.go b/pkg/log/glog.go index 47e22614b..553f7feb6 100644 --- a/pkg/log/glog.go +++ b/pkg/log/glog.go @@ -47,7 +47,7 @@ var pid = os.Getpid() // file The file name // line The line number // msg The user-supplied message -func (g GoogleEmitter) Emit(depth int, level Level, timestamp time.Time, format string, args ...interface{}) { +func (g GoogleEmitter) Emit(depth int, level Level, timestamp time.Time, format string, args ...any) { // Log level. prefix := byte('?') switch level { diff --git a/pkg/log/json.go b/pkg/log/json.go index 8c52dcc87..a7f55a9f9 100644 --- a/pkg/log/json.go +++ b/pkg/log/json.go @@ -62,7 +62,7 @@ type JSONEmitter struct { } // Emit implements Emitter.Emit. -func (e JSONEmitter) Emit(_ int, level Level, timestamp time.Time, format string, v ...interface{}) { +func (e JSONEmitter) Emit(_ int, level Level, timestamp time.Time, format string, v ...any) { j := jsonLog{ Msg: fmt.Sprintf(format, v...), Level: level, diff --git a/pkg/log/json_k8s.go b/pkg/log/json_k8s.go index 5883e95e1..0105c0682 100644 --- a/pkg/log/json_k8s.go +++ b/pkg/log/json_k8s.go @@ -33,7 +33,7 @@ type K8sJSONEmitter struct { } // Emit implements Emitter.Emit. -func (e K8sJSONEmitter) Emit(_ int, level Level, timestamp time.Time, format string, v ...interface{}) { +func (e K8sJSONEmitter) Emit(_ int, level Level, timestamp time.Time, format string, v ...any) { j := k8sJSONLog{ Log: fmt.Sprintf(format, v...), Level: level, diff --git a/pkg/log/log.go b/pkg/log/log.go index 7f8051e57..93d698924 100644 --- a/pkg/log/log.go +++ b/pkg/log/log.go @@ -80,7 +80,7 @@ func (l Level) String() string { type Emitter interface { // Emit emits the given log statement. This allows for control over the // timestamp used for logging. - Emit(depth int, level Level, timestamp time.Time, format string, v ...interface{}) + Emit(depth int, level Level, timestamp time.Time, format string, v ...any) } // Writer writes the output to the given writer. @@ -144,7 +144,7 @@ func (l *Writer) Write(data []byte) (int, error) { } // Emit emits the message. -func (l *Writer) Emit(_ int, _ Level, _ time.Time, format string, args ...interface{}) { +func (l *Writer) Emit(_ int, _ Level, _ time.Time, format string, args ...any) { fmt.Fprintf(l, format, args...) } @@ -152,7 +152,7 @@ func (l *Writer) Emit(_ int, _ Level, _ time.Time, format string, args ...interf type MultiEmitter []Emitter // Emit emits to all emitters. -func (m *MultiEmitter) Emit(depth int, level Level, timestamp time.Time, format string, v ...interface{}) { +func (m *MultiEmitter) Emit(depth int, level Level, timestamp time.Time, format string, v ...any) { for _, e := range *m { e.Emit(1+depth, level, timestamp, format, v...) } @@ -160,7 +160,7 @@ func (m *MultiEmitter) Emit(depth int, level Level, timestamp time.Time, format // TestLogger is implemented by testing.T and testing.B. type TestLogger interface { - Logf(format string, v ...interface{}) + Logf(format string, v ...any) } // TestEmitter may be used for wrapping tests. @@ -169,7 +169,7 @@ type TestEmitter struct { } // Emit emits to the TestLogger. -func (t *TestEmitter) Emit(_ int, level Level, timestamp time.Time, format string, v ...interface{}) { +func (t *TestEmitter) Emit(_ int, level Level, timestamp time.Time, format string, v ...any) { t.Logf(format, v...) } @@ -179,13 +179,13 @@ func (t *TestEmitter) Emit(_ int, level Level, timestamp time.Time, format strin // satisfies this interface, and may be passed around as a Logger. type Logger interface { // Debugf logs a debug statement. - Debugf(format string, v ...interface{}) + Debugf(format string, v ...any) // Infof logs at an info level. - Infof(format string, v ...interface{}) + Infof(format string, v ...any) // Warningf logs at a warning level. - Warningf(format string, v ...interface{}) + Warningf(format string, v ...any) // IsLogging returns true iff this level is being logged. This may be // used to short-circuit expensive operations for debugging calls. @@ -199,36 +199,36 @@ type BasicLogger struct { } // Debugf implements logger.Debugf. -func (l *BasicLogger) Debugf(format string, v ...interface{}) { +func (l *BasicLogger) Debugf(format string, v ...any) { l.DebugfAtDepth(1, format, v...) } // Infof implements logger.Infof. -func (l *BasicLogger) Infof(format string, v ...interface{}) { +func (l *BasicLogger) Infof(format string, v ...any) { l.InfofAtDepth(1, format, v...) } // Warningf implements logger.Warningf. -func (l *BasicLogger) Warningf(format string, v ...interface{}) { +func (l *BasicLogger) Warningf(format string, v ...any) { l.WarningfAtDepth(1, format, v...) } // DebugfAtDepth logs at a specific depth. -func (l *BasicLogger) DebugfAtDepth(depth int, format string, v ...interface{}) { +func (l *BasicLogger) DebugfAtDepth(depth int, format string, v ...any) { if l.IsLogging(Debug) { l.Emit(1+depth, Debug, time.Now(), format, v...) } } // InfofAtDepth logs at a specific depth. -func (l *BasicLogger) InfofAtDepth(depth int, format string, v ...interface{}) { +func (l *BasicLogger) InfofAtDepth(depth int, format string, v ...any) { if l.IsLogging(Info) { l.Emit(1+depth, Info, time.Now(), format, v...) } } // WarningfAtDepth logs at a specific depth. -func (l *BasicLogger) WarningfAtDepth(depth int, format string, v ...interface{}) { +func (l *BasicLogger) WarningfAtDepth(depth int, format string, v ...any) { if l.IsLogging(Warning) { l.Emit(1+depth, Warning, time.Now(), format, v...) } @@ -275,32 +275,32 @@ func SetLevel(newLevel Level) { } // Debugf logs to the global logger. -func Debugf(format string, v ...interface{}) { +func Debugf(format string, v ...any) { Log().DebugfAtDepth(1, format, v...) } // Infof logs to the global logger. -func Infof(format string, v ...interface{}) { +func Infof(format string, v ...any) { Log().InfofAtDepth(1, format, v...) } // Warningf logs to the global logger. -func Warningf(format string, v ...interface{}) { +func Warningf(format string, v ...any) { Log().WarningfAtDepth(1, format, v...) } // DebugfAtDepth logs to the global logger. -func DebugfAtDepth(depth int, format string, v ...interface{}) { +func DebugfAtDepth(depth int, format string, v ...any) { Log().DebugfAtDepth(1+depth, format, v...) } // InfofAtDepth logs to the global logger. -func InfofAtDepth(depth int, format string, v ...interface{}) { +func InfofAtDepth(depth int, format string, v ...any) { Log().InfofAtDepth(1+depth, format, v...) } // WarningfAtDepth logs to the global logger. -func WarningfAtDepth(depth int, format string, v ...interface{}) { +func WarningfAtDepth(depth int, format string, v ...any) { Log().WarningfAtDepth(1+depth, format, v...) } @@ -329,7 +329,7 @@ func Stacks(all bool) []byte { // goroutine. // // This will be print a traceback, tb, as Warningf(format+":\n%s", v..., tb). -func Traceback(format string, v ...interface{}) { +func Traceback(format string, v ...any) { v = append(v, Stacks(false)) Warningf(format+":\n%s", v...) } @@ -337,7 +337,7 @@ func Traceback(format string, v ...interface{}) { // TracebackAll logs the given message and dumps a stacktrace of all goroutines. // // This will be print a traceback, tb, as Warningf(format+":\n%s", v..., tb). -func TracebackAll(format string, v ...interface{}) { +func TracebackAll(format string, v ...any) { v = append(v, Stacks(true)) Warningf(format+":\n%s", v...) } @@ -350,7 +350,7 @@ func IsLogging(level Level) bool { // CopyStandardLogTo redirects the stdlib log package global output to the global // logger for the specified level. func CopyStandardLogTo(l Level) error { - var f func(string, ...interface{}) + var f func(string, ...any) switch l { case Debug: diff --git a/pkg/log/rate_limited.go b/pkg/log/rate_limited.go index 285d9b26d..e274238dc 100644 --- a/pkg/log/rate_limited.go +++ b/pkg/log/rate_limited.go @@ -25,19 +25,19 @@ type rateLimitedLogger struct { limit *rate.Limiter } -func (rl *rateLimitedLogger) Debugf(format string, v ...interface{}) { +func (rl *rateLimitedLogger) Debugf(format string, v ...any) { if rl.limit.Allow() { rl.logger.Debugf(format, v...) } } -func (rl *rateLimitedLogger) Infof(format string, v ...interface{}) { +func (rl *rateLimitedLogger) Infof(format string, v ...any) { if rl.limit.Allow() { rl.logger.Infof(format, v...) } } -func (rl *rateLimitedLogger) Warningf(format string, v ...interface{}) { +func (rl *rateLimitedLogger) Warningf(format string, v ...any) { if rl.limit.Allow() { rl.logger.Warningf(format, v...) } diff --git a/pkg/metric/metric.go b/pkg/metric/metric.go index aaa286f64..a126a8036 100644 --- a/pkg/metric/metric.go +++ b/pkg/metric/metric.go @@ -842,7 +842,7 @@ func (m *metricSet) Values() metricValues { m.mu.Unlock() vals := metricValues{ - uint64Metrics: make(map[string]interface{}, len(m.uint64Metrics)), + uint64Metrics: make(map[string]any, len(m.uint64Metrics)), distributionMetrics: make(map[string][][]uint64, len(m.distributionMetrics)), distributionTotalSamples: make(map[string][]uint64, len(m.distributionMetrics)), stages: stages, @@ -894,7 +894,7 @@ type metricValues struct { // uint64Metrics is a map of uint64 metrics, // with key as metric name. Value can be either uint64, or map[string]uint64 // to support metrics with one field. - uint64Metrics map[string]interface{} + uint64Metrics map[string]any // distributionMetrics is a map of distribution metrics. // The first key level is the metric name. diff --git a/pkg/metric/metric_test.go b/pkg/metric/metric_test.go index a8904e658..4856c8259 100644 --- a/pkg/metric/metric_test.go +++ b/pkg/metric/metric_test.go @@ -796,7 +796,7 @@ func TestBucketerPanics(t *testing.T) { }, } { t.Run(name, func(t *testing.T) { - var recovered interface{} + var recovered any func() { defer func() { recovered = recover() diff --git a/pkg/p9/client.go b/pkg/p9/client.go index 45ee59a92..279ec288c 100644 --- a/pkg/p9/client.go +++ b/pkg/p9/client.go @@ -61,7 +61,7 @@ type response struct { } var responsePool = sync.Pool{ - New: func() interface{} { + New: func() any { return &response{ done: make(chan error, 1), } diff --git a/pkg/p9/p9test/p9test.go b/pkg/p9/p9test/p9test.go index f0122ac20..a3e415314 100644 --- a/pkg/p9/p9test/p9test.go +++ b/pkg/p9/p9test/p9test.go @@ -87,7 +87,7 @@ func (m *Mock) RemoveChild(name string) { } // Matches implements gomock.Matcher.Matches. -func (m *Mock) Matches(x interface{}) bool { +func (m *Mock) Matches(x any) bool { if om, ok := x.(*Mock); ok { return m.QID.Path == om.QID.Path } diff --git a/pkg/p9/transport.go b/pkg/p9/transport.go index add607b9d..eed6654b2 100644 --- a/pkg/p9/transport.go +++ b/pkg/p9/transport.go @@ -64,7 +64,7 @@ const ( ) var dataPool = sync.Pool{ - New: func() interface{} { + New: func() any { // These buffers are used for decoding without a payload. // We need to return a pointer to avoid unnecessary allocations // (see https://staticcheck.io/docs/checks#SA6002). diff --git a/pkg/refs/refcounter.go b/pkg/refs/refcounter.go index a15b218fb..c0bb74ae9 100644 --- a/pkg/refs/refcounter.go +++ b/pkg/refs/refcounter.go @@ -81,7 +81,7 @@ type WeakRef struct { // weakRefPool is a pool of weak references to avoid allocations on the hot path. var weakRefPool = sync.Pool{ - New: func() interface{} { + New: func() any { return &WeakRef{} }, } @@ -262,7 +262,7 @@ func (l *LeakMode) Set(v string) error { } // Get implements flag.Value. -func (l *LeakMode) Get() interface{} { +func (l *LeakMode) Get() any { return *l } diff --git a/pkg/refs/refcounter_state.go b/pkg/refs/refcounter_state.go index 7c99fd2b5..7987b39a1 100644 --- a/pkg/refs/refcounter_state.go +++ b/pkg/refs/refcounter_state.go @@ -16,7 +16,7 @@ package refs // +stateify savable type savedReference struct { - obj interface{} + obj any } func (w *WeakRef) saveObj() savedReference { diff --git a/pkg/refsvfs2/refs_template.go b/pkg/refsvfs2/refs_template.go index 62b621768..871c7d49f 100644 --- a/pkg/refsvfs2/refs_template.go +++ b/pkg/refsvfs2/refs_template.go @@ -31,7 +31,7 @@ const enableLogging = false // T is the type of the reference counted object. It is only used to customize // debug output when leak checking. -type T interface{} +type T any // obj is used to customize logging. Note that we use a pointer to T so that // we do not copy the entire object when passed as a format parameter. diff --git a/pkg/ring0/kernel_unsafe.go b/pkg/ring0/kernel_unsafe.go index 04c60d0a7..ec4a9157b 100644 --- a/pkg/ring0/kernel_unsafe.go +++ b/pkg/ring0/kernel_unsafe.go @@ -27,7 +27,7 @@ type eface struct { // kernelAddr returns the kernel virtual address for the given object. // //go:nosplit -func kernelAddr(obj interface{}) uintptr { +func kernelAddr(obj any) uintptr { e := (*eface)(unsafe.Pointer(&obj)) return KernelStartAddress | uintptr(e.data) } diff --git a/pkg/seccomp/seccomp_rules.go b/pkg/seccomp/seccomp_rules.go index 5863b7092..02ab30741 100644 --- a/pkg/seccomp/seccomp_rules.go +++ b/pkg/seccomp/seccomp_rules.go @@ -105,7 +105,7 @@ func (a maskedEqual) String() (s string) { // MaskedEqual specifies a value that matches the input after the input is // masked (bitwise &) against the given mask. Can be used to verify that input // only includes certain approved flags. -func MaskedEqual(mask, value uintptr) interface{} { +func MaskedEqual(mask, value uintptr) any { return maskedEqual{ mask: mask, value: value, @@ -119,7 +119,7 @@ func MaskedEqual(mask, value uintptr) interface{} { // rule := Rule { // EqualTo(linux.ARCH_GET_FS | linux.ARCH_SET_FS), // arg0 // } -type Rule [7]interface{} // 6 arguments + RIP +type Rule [7]any // 6 arguments + RIP // RuleIP indicates what rules in the Rule array have to be applied to // instruction pointer. diff --git a/pkg/segment/set.go b/pkg/segment/set.go index aa2e33647..025e180bf 100644 --- a/pkg/segment/set.go +++ b/pkg/segment/set.go @@ -31,10 +31,10 @@ import ( type Key uint64 // Range is a required type parameter equivalent to Range. -type Range interface{} +type Range any // Value is a required type parameter. -type Value interface{} +type Value any // trackGaps is an optional parameter. // diff --git a/pkg/sentry/contexttest/contexttest.go b/pkg/sentry/contexttest/contexttest.go index eadd23e98..46caaebc5 100644 --- a/pkg/sentry/contexttest/contexttest.go +++ b/pkg/sentry/contexttest/contexttest.go @@ -60,7 +60,7 @@ func Context(tb testing.TB) context.Context { mf: mf, platform: p, creds: auth.NewAnonymousCredentials(), - otherValues: make(map[interface{}]interface{}), + otherValues: make(map[any]any), } } @@ -72,7 +72,7 @@ type TestContext struct { mf *pgalloc.MemoryFile platform platform.Platform creds *auth.Credentials - otherValues map[interface{}]interface{} + otherValues map[any]any } // globalUniqueID tracks incremental unique identifiers for tests. @@ -103,12 +103,12 @@ func (*hostClock) Now() ktime.Time { // RegisterValue registers additional values with this test context. Useful for // providing values from external packages that contexttest can't depend on. -func (t *TestContext) RegisterValue(key, value interface{}) { +func (t *TestContext) RegisterValue(key, value any) { t.otherValues[key] = value } // Value implements context.Context. -func (t *TestContext) Value(key interface{}) interface{} { +func (t *TestContext) Value(key any) any { switch key { case auth.CtxCredentials: return t.creds @@ -158,7 +158,7 @@ type limitContext struct { } // Value implements context.Context. -func (lc limitContext) Value(key interface{}) interface{} { +func (lc limitContext) Value(key any) any { switch key { case limits.CtxLimits: return lc.l diff --git a/pkg/sentry/fs/context.go b/pkg/sentry/fs/context.go index 0fbd60056..d03e07e6e 100644 --- a/pkg/sentry/fs/context.go +++ b/pkg/sentry/fs/context.go @@ -127,7 +127,7 @@ func WithRoot(ctx context.Context, root *Dirent) context.Context { } // Value implements Context.Value. -func (rc rootContext) Value(key interface{}) interface{} { +func (rc rootContext) Value(key any) any { switch key { case CtxRoot: rc.root.IncRef() diff --git a/pkg/sentry/fs/copy_up.go b/pkg/sentry/fs/copy_up.go index 0e8e2aca6..fb65be705 100644 --- a/pkg/sentry/fs/copy_up.go +++ b/pkg/sentry/fs/copy_up.go @@ -339,7 +339,7 @@ func cleanupUpper(ctx context.Context, parent *Inode, name string, copyUpErr err // copyUpBuffers is a buffer pool for copying file content. The buffer // size is the same used by io.Copy. var copyUpBuffers = sync.Pool{ - New: func() interface{} { + New: func() any { b := make([]byte, 8*hostarch.PageSize) return &b }, diff --git a/pkg/sentry/fs/dev/fs.go b/pkg/sentry/fs/dev/fs.go index 5e518fb63..feae825ce 100644 --- a/pkg/sentry/fs/dev/fs.go +++ b/pkg/sentry/fs/dev/fs.go @@ -57,7 +57,7 @@ func (*filesystem) Flags() fs.FilesystemFlags { } // Mount returns a devtmpfs root that can be positioned in the vfs. -func (f *filesystem) Mount(ctx context.Context, device string, flags fs.MountSourceFlags, data string, _ interface{}) (*fs.Inode, error) { +func (f *filesystem) Mount(ctx context.Context, device string, flags fs.MountSourceFlags, data string, _ any) (*fs.Inode, error) { // devtmpfs backed by ramfs ignores bad options. See fs/ramfs/inode.c:ramfs_parse_options. // -> we should consider parsing the mode and backing devtmpfs by this. return New(ctx, fs.NewNonCachingMountSource(ctx, f, flags)), nil diff --git a/pkg/sentry/fs/fdpipe/pipe_test.go b/pkg/sentry/fs/fdpipe/pipe_test.go index 63900e766..9ccf12dc4 100644 --- a/pkg/sentry/fs/fdpipe/pipe_test.go +++ b/pkg/sentry/fs/fdpipe/pipe_test.go @@ -193,7 +193,7 @@ func TestPipeRequest(t *testing.T) { desc string // request to execute. - context interface{} + context any // flags determines whether to use the read or write end // of the pipe, for this test it can only be Read or Write. diff --git a/pkg/sentry/fs/file_overlay_test.go b/pkg/sentry/fs/file_overlay_test.go index 1971cc680..49a2b7ef7 100644 --- a/pkg/sentry/fs/file_overlay_test.go +++ b/pkg/sentry/fs/file_overlay_test.go @@ -181,7 +181,7 @@ type rootContext struct { } // Value implements context.Context. -func (r *rootContext) Value(key interface{}) interface{} { +func (r *rootContext) Value(key any) any { switch key { case fs.CtxRoot: r.root.IncRef() diff --git a/pkg/sentry/fs/filesystems.go b/pkg/sentry/fs/filesystems.go index cd48f703c..25c719caa 100644 --- a/pkg/sentry/fs/filesystems.go +++ b/pkg/sentry/fs/filesystems.go @@ -50,7 +50,7 @@ type Filesystem interface { // data options. // // Mount may return arbitrary errors. They do not need syserr translations. - Mount(ctx context.Context, device string, flags MountSourceFlags, data string, dataObj interface{}) (*Inode, error) + Mount(ctx context.Context, device string, flags MountSourceFlags, data string, dataObj any) (*Inode, error) // AllowUserMount determines whether mount(2) is allowed to mount a // file system of this type. diff --git a/pkg/sentry/fs/gofer/fs.go b/pkg/sentry/fs/gofer/fs.go index 8ae2d78d7..69095e6fe 100644 --- a/pkg/sentry/fs/gofer/fs.go +++ b/pkg/sentry/fs/gofer/fs.go @@ -128,7 +128,7 @@ func (*filesystem) Flags() fs.FilesystemFlags { } // Mount returns an attached 9p client that can be positioned in the vfs. -func (f *filesystem) Mount(ctx context.Context, device string, flags fs.MountSourceFlags, data string, _ interface{}) (*fs.Inode, error) { +func (f *filesystem) Mount(ctx context.Context, device string, flags fs.MountSourceFlags, data string, _ any) (*fs.Inode, error) { // Parse and validate the mount options. o, err := options(data) if err != nil { diff --git a/pkg/sentry/fs/gofer/inode_state.go b/pkg/sentry/fs/gofer/inode_state.go index 19f91f010..bb7abc741 100644 --- a/pkg/sentry/fs/gofer/inode_state.go +++ b/pkg/sentry/fs/gofer/inode_state.go @@ -50,7 +50,7 @@ type dummyClockContext struct { } // Value implements context.Context -func (d *dummyClockContext) Value(key interface{}) interface{} { +func (d *dummyClockContext) Value(key any) any { switch key { case time.CtxRealtimeClock: return &dummyClock{} diff --git a/pkg/sentry/fs/host/host.go b/pkg/sentry/fs/host/host.go index 9f6dbd7e9..2ab2560ac 100644 --- a/pkg/sentry/fs/host/host.go +++ b/pkg/sentry/fs/host/host.go @@ -39,7 +39,7 @@ func (*filesystem) Name() string { } // Mount returns an error. Mounting hostfs is not allowed. -func (*filesystem) Mount(ctx context.Context, device string, flags fs.MountSourceFlags, data string, dataObj interface{}) (*fs.Inode, error) { +func (*filesystem) Mount(ctx context.Context, device string, flags fs.MountSourceFlags, data string, dataObj any) (*fs.Inode, error) { return nil, linuxerr.EPERM } diff --git a/pkg/sentry/fs/lock/lock.go b/pkg/sentry/fs/lock/lock.go index 6b522142e..99dbdba93 100644 --- a/pkg/sentry/fs/lock/lock.go +++ b/pkg/sentry/fs/lock/lock.go @@ -65,7 +65,7 @@ import ( type LockType int // UniqueID is a unique identifier of the holder of a regional file lock. -type UniqueID interface{} +type UniqueID any const ( // ReadLock describes a POSIX regional file lock to be taken diff --git a/pkg/sentry/fs/mount_overlay.go b/pkg/sentry/fs/mount_overlay.go index 7badc75d6..cdc0d1024 100644 --- a/pkg/sentry/fs/mount_overlay.go +++ b/pkg/sentry/fs/mount_overlay.go @@ -146,6 +146,6 @@ func (*overlayFilesystem) AllowUserList() bool { } // Mount implements Filesystem.Mount. -func (ofs *overlayFilesystem) Mount(ctx context.Context, device string, flags MountSourceFlags, data string, _ interface{}) (*Inode, error) { +func (ofs *overlayFilesystem) Mount(ctx context.Context, device string, flags MountSourceFlags, data string, _ any) (*Inode, error) { panic("overlayFilesystem.Mount should not be called!") } diff --git a/pkg/sentry/fs/proc/fs.go b/pkg/sentry/fs/proc/fs.go index daf1ba781..52b6ccbcc 100644 --- a/pkg/sentry/fs/proc/fs.go +++ b/pkg/sentry/fs/proc/fs.go @@ -59,7 +59,7 @@ func (*filesystem) Flags() fs.FilesystemFlags { } // Mount returns the root of a procfs that can be positioned in the vfs. -func (f *filesystem) Mount(ctx context.Context, device string, flags fs.MountSourceFlags, data string, cgroupsInt interface{}) (*fs.Inode, error) { +func (f *filesystem) Mount(ctx context.Context, device string, flags fs.MountSourceFlags, data string, cgroupsInt any) (*fs.Inode, error) { // device is always ignored. // Parse generic comma-separated key=value options, this file system expects them. diff --git a/pkg/sentry/fs/proc/net.go b/pkg/sentry/fs/proc/net.go index 57dacf9a3..6d5f4e5e1 100644 --- a/pkg/sentry/fs/proc/net.go +++ b/pkg/sentry/fs/proc/net.go @@ -255,7 +255,7 @@ var snmp = []snmpLine{ }, } -func toSlice(a interface{}) []uint64 { +func toSlice(a any) []uint64 { v := reflect.Indirect(reflect.ValueOf(a)) return v.Slice(0, v.Len()).Interface().([]uint64) } @@ -272,7 +272,7 @@ func sprintSlice(s []uint64) string { // net/core/net-procfs.c:dev_seq_show. func (n *netSnmp) ReadSeqFileData(ctx context.Context, h seqfile.SeqHandle) ([]seqfile.SeqData, int64) { contents := make([]string, 0, len(snmp)*2) - types := []interface{}{ + types := []any{ &inet.StatSNMPIP{}, &inet.StatSNMPICMP{}, nil, // TODO(gvisor.dev/issue/628): Support IcmpMsg stats. diff --git a/pkg/sentry/fs/proc/seqfile/seqfile.go b/pkg/sentry/fs/proc/seqfile/seqfile.go index 77270814e..69a2ad0e9 100644 --- a/pkg/sentry/fs/proc/seqfile/seqfile.go +++ b/pkg/sentry/fs/proc/seqfile/seqfile.go @@ -32,7 +32,7 @@ import ( ) // SeqHandle is a helper handle to seek in the file. -type SeqHandle interface{} +type SeqHandle any // SeqData holds the data for one unit in the file. // diff --git a/pkg/sentry/fs/restore.go b/pkg/sentry/fs/restore.go index 64c6a6ae9..5fb4d8279 100644 --- a/pkg/sentry/fs/restore.go +++ b/pkg/sentry/fs/restore.go @@ -45,7 +45,7 @@ type MountArgs struct { DataString string // DataObj corresponds to the data interface argument of Mount. - DataObj interface{} + DataObj any } // restoreEnv holds the fs package global RestoreEnvironment. diff --git a/pkg/sentry/fs/sys/fs.go b/pkg/sentry/fs/sys/fs.go index fd03a4e38..01c4f4944 100644 --- a/pkg/sentry/fs/sys/fs.go +++ b/pkg/sentry/fs/sys/fs.go @@ -57,7 +57,7 @@ func (*filesystem) Flags() fs.FilesystemFlags { } // Mount returns a sysfs root which can be positioned in the vfs. -func (f *filesystem) Mount(ctx context.Context, device string, flags fs.MountSourceFlags, data string, _ interface{}) (*fs.Inode, error) { +func (f *filesystem) Mount(ctx context.Context, device string, flags fs.MountSourceFlags, data string, _ any) (*fs.Inode, error) { // device is always ignored. // sysfs ignores data, see fs/sysfs/mount.c:sysfs_mount. diff --git a/pkg/sentry/fs/tmpfs/fs.go b/pkg/sentry/fs/tmpfs/fs.go index b48d475ed..e8091318e 100644 --- a/pkg/sentry/fs/tmpfs/fs.go +++ b/pkg/sentry/fs/tmpfs/fs.go @@ -89,7 +89,7 @@ func (*Filesystem) Flags() fs.FilesystemFlags { } // Mount returns a tmpfs root that can be positioned in the vfs. -func (f *Filesystem) Mount(ctx context.Context, device string, flags fs.MountSourceFlags, data string, _ interface{}) (*fs.Inode, error) { +func (f *Filesystem) Mount(ctx context.Context, device string, flags fs.MountSourceFlags, data string, _ any) (*fs.Inode, error) { // device is always ignored. // Parse generic comma-separated key=value options, this file system expects them. diff --git a/pkg/sentry/fs/tty/fs.go b/pkg/sentry/fs/tty/fs.go index 0e5916380..498e08db4 100644 --- a/pkg/sentry/fs/tty/fs.go +++ b/pkg/sentry/fs/tty/fs.go @@ -59,7 +59,7 @@ func (*filesystem) Flags() fs.FilesystemFlags { } // MountSource returns a devpts root that can be positioned in the vfs. -func (f *filesystem) Mount(ctx context.Context, device string, flags fs.MountSourceFlags, data string, _ interface{}) (*fs.Inode, error) { +func (f *filesystem) Mount(ctx context.Context, device string, flags fs.MountSourceFlags, data string, _ any) (*fs.Inode, error) { // device is always ignored. // No options are supported. diff --git a/pkg/sentry/fsimpl/devtmpfs/devtmpfs.go b/pkg/sentry/fsimpl/devtmpfs/devtmpfs.go index daff40cd5..8b75a2c39 100644 --- a/pkg/sentry/fsimpl/devtmpfs/devtmpfs.go +++ b/pkg/sentry/fsimpl/devtmpfs/devtmpfs.go @@ -127,7 +127,7 @@ func (a *Accessor) wrapContext(ctx context.Context) *accessorContext { } // Value implements context.Context.Value. -func (ac *accessorContext) Value(key interface{}) interface{} { +func (ac *accessorContext) Value(key any) any { switch key { case vfs.CtxMountNamespace: ac.a.mntns.IncRef() diff --git a/pkg/sentry/fsimpl/gofer/filesystem.go b/pkg/sentry/fsimpl/gofer/filesystem.go index 517e5b7cf..f2cea329e 100644 --- a/pkg/sentry/fsimpl/gofer/filesystem.go +++ b/pkg/sentry/fsimpl/gofer/filesystem.go @@ -117,11 +117,11 @@ const MaxFilenameLen = (1 << 16) - 1 // dentrySlicePool is a pool of *[]*dentry used to store dentries for which // dentry.checkCachingLocked() must be called. The pool holds pointers to -// slices because Go lacks generics, so sync.Pool operates on interface{}, so +// slices because Go lacks generics, so sync.Pool operates on any, so // every call to (what should be) sync.Pool<[]*dentry>.Put() allocates a copy // of the slice header on the heap. var dentrySlicePool = sync.Pool{ - New: func() interface{} { + New: func() any { ds := make([]*dentry, 0, 4) // arbitrary non-zero initial capacity return &ds }, @@ -1878,7 +1878,7 @@ func (fs *filesystem) PrependPath(ctx context.Context, vfsroot, vd vfs.VirtualDe type mopt struct { key string - value interface{} + value any } func (m mopt) String() string { diff --git a/pkg/sentry/fsimpl/gofer/handle.go b/pkg/sentry/fsimpl/gofer/handle.go index b8bf5c6e5..3bf90b43d 100644 --- a/pkg/sentry/fsimpl/gofer/handle.go +++ b/pkg/sentry/fsimpl/gofer/handle.go @@ -156,7 +156,7 @@ type handleReadWriter struct { } var handleReadWriterPool = sync.Pool{ - New: func() interface{} { + New: func() any { return &handleReadWriter{} }, } diff --git a/pkg/sentry/fsimpl/gofer/regular_file.go b/pkg/sentry/fsimpl/gofer/regular_file.go index 8ffb0b92a..6117d8bf3 100644 --- a/pkg/sentry/fsimpl/gofer/regular_file.go +++ b/pkg/sentry/fsimpl/gofer/regular_file.go @@ -365,7 +365,7 @@ type dentryReadWriter struct { } var dentryReadWriterPool = sync.Pool{ - New: func() interface{} { + New: func() any { return &dentryReadWriter{} }, } diff --git a/pkg/sentry/fsimpl/gofer/revalidate.go b/pkg/sentry/fsimpl/gofer/revalidate.go index 782f0d02d..3fd0c1963 100644 --- a/pkg/sentry/fsimpl/gofer/revalidate.go +++ b/pkg/sentry/fsimpl/gofer/revalidate.go @@ -348,7 +348,7 @@ func (fs *filesystem) revalidateHelper(ctx context.Context, vfsObj *vfs.VirtualF // revalidateStatePool caches revalidateState instances to save array // allocations for dentries and names. var revalidateStatePool = sync.Pool{ - New: func() interface{} { + New: func() any { return &revalidateState{} }, } diff --git a/pkg/sentry/fsimpl/overlay/filesystem.go b/pkg/sentry/fsimpl/overlay/filesystem.go index af97e324f..03838c848 100644 --- a/pkg/sentry/fsimpl/overlay/filesystem.go +++ b/pkg/sentry/fsimpl/overlay/filesystem.go @@ -53,7 +53,7 @@ func (fs *filesystem) Sync(ctx context.Context) error { } var dentrySlicePool = sync.Pool{ - New: func() interface{} { + New: func() any { ds := make([]*dentry, 0, 4) // arbitrary non-zero initial capacity return &ds }, diff --git a/pkg/sentry/fsimpl/proc/task_net.go b/pkg/sentry/fsimpl/proc/task_net.go index a99efdc67..29a9b1516 100644 --- a/pkg/sentry/fsimpl/proc/task_net.go +++ b/pkg/sentry/fsimpl/proc/task_net.go @@ -650,7 +650,7 @@ var snmp = []snmpLine{ }, } -func toSlice(a interface{}) []uint64 { +func toSlice(a any) []uint64 { v := reflect.Indirect(reflect.ValueOf(a)) return v.Slice(0, v.Len()).Interface().([]uint64) } @@ -665,7 +665,7 @@ func sprintSlice(s []uint64) string { // Generate implements vfs.DynamicBytesSource.Generate. func (d *netSnmpData) Generate(ctx context.Context, buf *bytes.Buffer) error { - types := []interface{}{ + types := []any{ &inet.StatSNMPIP{}, &inet.StatSNMPICMP{}, nil, // TODO(gvisor.dev/issue/628): Support IcmpMsg stats. diff --git a/pkg/sentry/fsimpl/tmpfs/regular_file.go b/pkg/sentry/fsimpl/tmpfs/regular_file.go index 556025086..71fb9d203 100644 --- a/pkg/sentry/fsimpl/tmpfs/regular_file.go +++ b/pkg/sentry/fsimpl/tmpfs/regular_file.go @@ -568,7 +568,7 @@ type regularFileReadWriter struct { } var regularFileReadWriterPool = sync.Pool{ - New: func() interface{} { + New: func() any { return ®ularFileReadWriter{} }, } diff --git a/pkg/sentry/fsimpl/tmpfs/tmpfs.go b/pkg/sentry/fsimpl/tmpfs/tmpfs.go index 3384c53f5..daa452797 100644 --- a/pkg/sentry/fsimpl/tmpfs/tmpfs.go +++ b/pkg/sentry/fsimpl/tmpfs/tmpfs.go @@ -450,12 +450,12 @@ type inode struct { // Inotify watches for this inode. watches vfs.Watches - impl interface{} // immutable + impl any // immutable } const maxLinks = math.MaxUint32 -func (i *inode) init(impl interface{}, fs *filesystem, kuid auth.KUID, kgid auth.KGID, mode linux.FileMode, parentDir *directory) { +func (i *inode) init(impl any, fs *filesystem, kuid auth.KUID, kgid auth.KGID, mode linux.FileMode, parentDir *directory) { if mode.FileType() == 0 { panic("file type is required in FileMode") } diff --git a/pkg/sentry/hostfd/hostfd.go b/pkg/sentry/hostfd/hostfd.go index 70dd9cafb..e2ec20b99 100644 --- a/pkg/sentry/hostfd/hostfd.go +++ b/pkg/sentry/hostfd/hostfd.go @@ -32,7 +32,7 @@ type ReadWriterAt struct { } var rwpool = sync.Pool{ - New: func() interface{} { + New: func() any { return &ReadWriterAt{} }, } diff --git a/pkg/sentry/inet/inet.go b/pkg/sentry/inet/inet.go index 5daa76b1f..c081a7b48 100644 --- a/pkg/sentry/inet/inet.go +++ b/pkg/sentry/inet/inet.go @@ -74,7 +74,7 @@ type Stack interface { SetTCPRecovery(recovery TCPLossRecovery) error // Statistics reports stack statistics. - Statistics(stat interface{}, arg string) error + Statistics(stat any, arg string) error // RouteTable returns the network stack's route table. RouteTable() []Route diff --git a/pkg/sentry/inet/test_stack.go b/pkg/sentry/inet/test_stack.go index e04f2c144..6be707b6a 100644 --- a/pkg/sentry/inet/test_stack.go +++ b/pkg/sentry/inet/test_stack.go @@ -139,7 +139,7 @@ func (s *TestStack) SetTCPRecovery(recovery TCPLossRecovery) error { } // Statistics implements Stack. -func (s *TestStack) Statistics(stat interface{}, arg string) error { +func (s *TestStack) Statistics(stat any, arg string) error { return nil } diff --git a/pkg/sentry/kernel/auth/context.go b/pkg/sentry/kernel/auth/context.go index 2039a96ad..e1a6cdac5 100644 --- a/pkg/sentry/kernel/auth/context.go +++ b/pkg/sentry/kernel/auth/context.go @@ -59,7 +59,7 @@ type authContext struct { } // Value implements context.Context. -func (ac *authContext) Value(key interface{}) interface{} { +func (ac *authContext) Value(key any) any { switch key { case CtxCredentials: return ac.creds diff --git a/pkg/sentry/kernel/kcov.go b/pkg/sentry/kernel/kcov.go index 125ba5b1d..c974d807f 100644 --- a/pkg/sentry/kernel/kcov.go +++ b/pkg/sentry/kernel/kcov.go @@ -79,7 +79,7 @@ func (k *Kernel) NewKcov() *Kcov { } var coveragePool = sync.Pool{ - New: func() interface{} { + New: func() any { return make([]byte, 0) }, } diff --git a/pkg/sentry/kernel/kernel.go b/pkg/sentry/kernel/kernel.go index 0f6defcda..34ef07fcd 100644 --- a/pkg/sentry/kernel/kernel.go +++ b/pkg/sentry/kernel/kernel.go @@ -816,7 +816,7 @@ type createProcessContext struct { } // Value implements context.Context.Value. -func (ctx *createProcessContext) Value(key interface{}) interface{} { +func (ctx *createProcessContext) Value(key any) any { switch key { case CtxKernel: return ctx.kernel @@ -1592,7 +1592,7 @@ func (*Kernel) Err() error { } // Value implements context.Context. -func (ctx *supervisorContext) Value(key interface{}) interface{} { +func (ctx *supervisorContext) Value(key any) any { switch key { case CtxCanTrace: // The supervisor context can trace anything. (None of diff --git a/pkg/sentry/kernel/syscalls.go b/pkg/sentry/kernel/syscalls.go index 96696dd7a..fe9877a1f 100644 --- a/pkg/sentry/kernel/syscalls.go +++ b/pkg/sentry/kernel/syscalls.go @@ -272,10 +272,10 @@ type Stracer interface { // SyscallEnter is called on syscall entry. // // The returned private data is passed to SyscallExit. - SyscallEnter(t *Task, sysno uintptr, args arch.SyscallArguments, flags uint32) interface{} + SyscallEnter(t *Task, sysno uintptr, args arch.SyscallArguments, flags uint32) any // SyscallExit is called on syscall exit. - SyscallExit(context interface{}, t *Task, sysno, rval uintptr, err error) + SyscallExit(context any, t *Task, sysno, rval uintptr, err error) } // SyscallTable is a lookup table of system calls. diff --git a/pkg/sentry/kernel/task_context.go b/pkg/sentry/kernel/task_context.go index 54d145921..d4c25352f 100644 --- a/pkg/sentry/kernel/task_context.go +++ b/pkg/sentry/kernel/task_context.go @@ -52,7 +52,7 @@ func (*Task) Err() error { // Value implements context.Context.Value. // // Preconditions: The caller must be running on the task goroutine. -func (t *Task) Value(key interface{}) interface{} { +func (t *Task) Value(key any) any { // This function is very hot; skip this check outside of +race builds. if sync.RaceEnabled { t.assertTaskGoroutine() @@ -60,7 +60,7 @@ func (t *Task) Value(key interface{}) interface{} { return t.contextValue(key, true /* isTaskGoroutine */) } -func (t *Task) contextValue(key interface{}, isTaskGoroutine bool) interface{} { +func (t *Task) contextValue(key any, isTaskGoroutine bool) any { switch key { case CtxCanTrace: return t.CanTrace @@ -154,7 +154,7 @@ type taskAsyncContext struct { } // Value implements context.Context.Value. -func (t *taskAsyncContext) Value(key interface{}) interface{} { +func (t *taskAsyncContext) Value(key any) any { return t.fallbackTask.contextValue(key, false /* isTaskGoroutine */) } diff --git a/pkg/sentry/kernel/task_image.go b/pkg/sentry/kernel/task_image.go index 157abd5e6..1e75e9f05 100644 --- a/pkg/sentry/kernel/task_image.go +++ b/pkg/sentry/kernel/task_image.go @@ -30,7 +30,7 @@ import ( var errNoSyscalls = syserr.New("no syscall table found", errno.ENOEXEC) // Auxmap contains miscellaneous data for the task. -type Auxmap map[string]interface{} +type Auxmap map[string]any // TaskImage is the subset of a task's data that is provided by the loader. // diff --git a/pkg/sentry/kernel/task_log.go b/pkg/sentry/kernel/task_log.go index 2cd317a35..2d2da7fd8 100644 --- a/pkg/sentry/kernel/task_log.go +++ b/pkg/sentry/kernel/task_log.go @@ -35,21 +35,21 @@ const ( ) // Infof logs an formatted info message by calling log.Infof. -func (t *Task) Infof(fmt string, v ...interface{}) { +func (t *Task) Infof(fmt string, v ...any) { if log.IsLogging(log.Info) { log.InfofAtDepth(1, t.logPrefix.Load().(string)+fmt, v...) } } // Warningf logs a warning string by calling log.Warningf. -func (t *Task) Warningf(fmt string, v ...interface{}) { +func (t *Task) Warningf(fmt string, v ...any) { if log.IsLogging(log.Warning) { log.WarningfAtDepth(1, t.logPrefix.Load().(string)+fmt, v...) } } // Debugf creates a debug string that includes the task ID. -func (t *Task) Debugf(fmt string, v ...interface{}) { +func (t *Task) Debugf(fmt string, v ...any) { if log.IsLogging(log.Debug) { log.DebugfAtDepth(1, t.logPrefix.Load().(string)+fmt, v...) } diff --git a/pkg/sentry/kernel/task_syscall.go b/pkg/sentry/kernel/task_syscall.go index 8b875cce5..31e934507 100644 --- a/pkg/sentry/kernel/task_syscall.go +++ b/pkg/sentry/kernel/task_syscall.go @@ -85,7 +85,7 @@ func (t *Task) executeSyscall(sysno uintptr, args arch.SyscallArguments) (rval u fe := s.FeatureEnable.Word(sysno) - var straceContext interface{} + var straceContext any if bits.IsAnyOn32(fe, StraceEnableBits) { straceContext = s.Stracer.SyscallEnter(t, sysno, args, fe) } diff --git a/pkg/sentry/loader/vdso.go b/pkg/sentry/loader/vdso.go index 1abb5141d..94de24af2 100644 --- a/pkg/sentry/loader/vdso.go +++ b/pkg/sentry/loader/vdso.go @@ -42,7 +42,7 @@ type fileContext struct { context.Context } -func (f *fileContext) Value(key interface{}) interface{} { +func (f *fileContext) Value(key any) any { switch key { case uniqueid.CtxGlobalUniqueID: return uint64(0) diff --git a/pkg/sentry/mm/address_space.go b/pkg/sentry/mm/address_space.go index 16603a580..3bd1d3589 100644 --- a/pkg/sentry/mm/address_space.go +++ b/pkg/sentry/mm/address_space.go @@ -79,7 +79,7 @@ func (mm *MemoryManager) Activate(ctx context.Context) error { // Get a new address space. We must force unmapping by passing nil to // NewAddressSpace if requested. (As in the nil interface object, not a // typed nil.) - mappingsID := (interface{})(mm) + mappingsID := (any)(mm) if mm.unmapAllOnActivate { mappingsID = nil } diff --git a/pkg/sentry/mm/aio_context.go b/pkg/sentry/mm/aio_context.go index 610556922..dd1879810 100644 --- a/pkg/sentry/mm/aio_context.go +++ b/pkg/sentry/mm/aio_context.go @@ -95,7 +95,7 @@ func (a *aioManager) lookupAIOContext(id uint64) (*AIOContext, bool) { // // +stateify savable type ioResult struct { - data interface{} + data any ioEntry } @@ -160,7 +160,7 @@ func (ctx *AIOContext) Prepare() error { // PopRequest pops a completed request if available, this function does not do // any blocking. Returns false if no request is available. -func (ctx *AIOContext) PopRequest() (interface{}, bool) { +func (ctx *AIOContext) PopRequest() (any, bool) { ctx.mu.Lock() defer ctx.mu.Unlock() @@ -179,7 +179,7 @@ func (ctx *AIOContext) PopRequest() (interface{}, bool) { // FinishRequest finishes a pending request. It queues up the data // and notifies listeners. -func (ctx *AIOContext) FinishRequest(data interface{}) { +func (ctx *AIOContext) FinishRequest(data any) { ctx.mu.Lock() defer ctx.mu.Unlock() diff --git a/pkg/sentry/platform/kvm/kvm.go b/pkg/sentry/platform/kvm/kvm.go index 20caddb89..57f01e92e 100644 --- a/pkg/sentry/platform/kvm/kvm.go +++ b/pkg/sentry/platform/kvm/kvm.go @@ -161,7 +161,7 @@ func (*KVM) MaxUserAddress() hostarch.Addr { } // NewAddressSpace returns a new pagetable root. -func (k *KVM) NewAddressSpace(interface{}) (platform.AddressSpace, <-chan struct{}, error) { +func (k *KVM) NewAddressSpace(any) (platform.AddressSpace, <-chan struct{}, error) { // Allocate page tables and install system mappings. pageTables := pagetables.NewWithUpper(newAllocator(), k.machine.upperSharedPageTables, ring0.KernelStartAddress) diff --git a/pkg/sentry/platform/kvm/kvm_test.go b/pkg/sentry/platform/kvm/kvm_test.go index d2c08209d..e82a9e3d3 100644 --- a/pkg/sentry/platform/kvm/kvm_test.go +++ b/pkg/sentry/platform/kvm/kvm_test.go @@ -35,8 +35,8 @@ import ( var dummyFPState = fpu.NewState() type testHarness interface { - Errorf(format string, args ...interface{}) - Fatalf(format string, args ...interface{}) + Errorf(format string, args ...any) + Fatalf(format string, args ...any) } func kvmTest(t testHarness, setup func(*KVM), fn func(*vCPU) bool) { diff --git a/pkg/sentry/platform/kvm/testutil/testutil.go b/pkg/sentry/platform/kvm/testutil/testutil.go index d8c273796..6b78b42df 100644 --- a/pkg/sentry/platform/kvm/testutil/testutil.go +++ b/pkg/sentry/platform/kvm/testutil/testutil.go @@ -73,7 +73,7 @@ func (r RegisterMismatchError) Error() string { } // addRegisterMisatch allows simple chaining of register mismatches. -func addRegisterMismatch(err error, reg string, got, expected interface{}) error { +func addRegisterMismatch(err error, reg string, got, expected any) error { errStr := fmt.Sprintf("%s got %08x, expected %08x", reg, got, expected) switch r := err.(type) { case nil: diff --git a/pkg/sentry/platform/platform.go b/pkg/sentry/platform/platform.go index fc4e0b9cc..d776ca3af 100644 --- a/pkg/sentry/platform/platform.go +++ b/pkg/sentry/platform/platform.go @@ -89,7 +89,7 @@ type Platform interface { // // In general, this blocking behavior only occurs when // CooperativelySchedulesAddressSpace (above) returns false. - NewAddressSpace(mappingsID interface{}) (AddressSpace, <-chan struct{}, error) + NewAddressSpace(mappingsID any) (AddressSpace, <-chan struct{}, error) // NewContext returns a new execution context. NewContext(context.Context) Context diff --git a/pkg/sentry/platform/ptrace/ptrace.go b/pkg/sentry/platform/ptrace/ptrace.go index 4286518e0..7e6c2fbb1 100644 --- a/pkg/sentry/platform/ptrace/ptrace.go +++ b/pkg/sentry/platform/ptrace/ptrace.go @@ -254,7 +254,7 @@ func (*PTrace) MaxUserAddress() hostarch.Addr { } // NewAddressSpace returns a new subprocess. -func (p *PTrace) NewAddressSpace(interface{}) (platform.AddressSpace, <-chan struct{}, error) { +func (p *PTrace) NewAddressSpace(any) (platform.AddressSpace, <-chan struct{}, error) { as, err := newSubprocess(globalPool.master.createStub) return as, nil, err } diff --git a/pkg/sentry/seccheck/config.go b/pkg/sentry/seccheck/config.go index 81e505d62..8271773ea 100644 --- a/pkg/sentry/seccheck/config.go +++ b/pkg/sentry/seccheck/config.go @@ -59,7 +59,7 @@ type SinkConfig struct { // Name is the sink to be created. The sink must exist in the system. Name string `json:"name,omitempty"` // Config is a opaque json object that is passed to the sink. - Config map[string]interface{} `json:"config,omitempty"` + Config map[string]any `json:"config,omitempty"` // IgnoreSetupError makes errors during sink setup to be ignored. Otherwise, // failures will prevent the container from starting. IgnoreSetupError bool `json:"ignore_setup_error,omitempty"` diff --git a/pkg/sentry/seccheck/metadata.go b/pkg/sentry/seccheck/metadata.go index 2267608ac..077751b11 100644 --- a/pkg/sentry/seccheck/metadata.go +++ b/pkg/sentry/seccheck/metadata.go @@ -115,11 +115,11 @@ type SinkDesc struct { // allow the sink to do whatever is necessary to set it up. If it returns a // file, this file is donated to the sandbox and passed to the sink when New // is called. config is an opaque json object passed to the sink. - Setup func(config map[string]interface{}) (*os.File, error) + Setup func(config map[string]any) (*os.File, error) // New creates a new sink. config is an opaque json object passed to the sink. // endpoing is a file descriptor to the file returned in Setup. It's set to -1 // if Setup returned nil. - New func(config map[string]interface{}, endpoint *fd.FD) (Sink, error) + New func(config map[string]any, endpoint *fd.FD) (Sink, error) } // RegisterSink registers a new sink to make it discoverable. diff --git a/pkg/sentry/seccheck/sinks/null/null.go b/pkg/sentry/seccheck/sinks/null/null.go index f4d234e41..0056f1b77 100644 --- a/pkg/sentry/seccheck/sinks/null/null.go +++ b/pkg/sentry/seccheck/sinks/null/null.go @@ -37,7 +37,7 @@ type null struct { var _ seccheck.Sink = (*null)(nil) -func new(_ map[string]interface{}, _ *fd.FD) (seccheck.Sink, error) { +func new(_ map[string]any, _ *fd.FD) (seccheck.Sink, error) { return &null{}, nil } diff --git a/pkg/sentry/seccheck/sinks/remote/remote.go b/pkg/sentry/seccheck/sinks/remote/remote.go index 95e9292b7..0d1806dc7 100644 --- a/pkg/sentry/seccheck/sinks/remote/remote.go +++ b/pkg/sentry/seccheck/sinks/remote/remote.go @@ -65,7 +65,7 @@ var _ seccheck.Sink = (*remote)(nil) // setupSink starts the connection to the remote process and returns a file that // can be used to communicate with it. The caller is responsible to close to // file. -func setupSink(config map[string]interface{}) (*os.File, error) { +func setupSink(config map[string]any) (*os.File, error) { addrOpaque, ok := config["endpoint"] if !ok { return nil, fmt.Errorf("endpoint not present in configuration") @@ -133,7 +133,7 @@ func setup(path string) (*os.File, error) { return f, nil } -func parseDuration(config map[string]interface{}, name string) (bool, time.Duration, error) { +func parseDuration(config map[string]any, name string) (bool, time.Duration, error) { opaque, ok := config[name] if !ok { return false, 0, nil @@ -150,7 +150,7 @@ func parseDuration(config map[string]interface{}, name string) (bool, time.Durat } // new creates a new Remote sink. -func new(config map[string]interface{}, endpoint *fd.FD) (seccheck.Sink, error) { +func new(config map[string]any, endpoint *fd.FD) (seccheck.Sink, error) { if endpoint == nil { return nil, fmt.Errorf("remote sink requires an endpoint") } diff --git a/pkg/sentry/seccheck/sinks/remote/remote_test.go b/pkg/sentry/seccheck/sinks/remote/remote_test.go index ea2fdbe9c..9640e1d12 100644 --- a/pkg/sentry/seccheck/sinks/remote/remote_test.go +++ b/pkg/sentry/seccheck/sinks/remote/remote_test.go @@ -231,13 +231,13 @@ func TestExample(t *testing.T) { func TestConfig(t *testing.T) { for _, tc := range []struct { name string - config map[string]interface{} + config map[string]any want *remote err string }{ { name: "default", - config: map[string]interface{}{}, + config: map[string]any{}, want: &remote{ retries: 0, initialBackoff: 25 * time.Microsecond, @@ -246,7 +246,7 @@ func TestConfig(t *testing.T) { }, { name: "all", - config: map[string]interface{}{ + config: map[string]any{ "retries": float64(10), "backoff": "1s", "backoff_max": "10s", @@ -259,28 +259,28 @@ func TestConfig(t *testing.T) { }, { name: "bad-retries", - config: map[string]interface{}{ + config: map[string]any{ "retries": "10", }, err: "retries", }, { name: "bad-backoff", - config: map[string]interface{}{ + config: map[string]any{ "backoff": "wrong", }, err: "invalid duration", }, { name: "bad-backoff-max", - config: map[string]interface{}{ + config: map[string]any{ "backoff_max": 10, }, err: "is not an string", }, { name: "bad-invalid-backoffs", - config: map[string]interface{}{ + config: map[string]any{ "retries": float64(10), "backoff": "10s", "backoff_max": "1s", diff --git a/pkg/sentry/socket/control/control.go b/pkg/sentry/socket/control/control.go index c98947da0..fd9db941c 100644 --- a/pkg/sentry/socket/control/control.go +++ b/pkg/sentry/socket/control/control.go @@ -527,7 +527,7 @@ func CmsgsSpace(t *kernel.Task, cmsgs socket.ControlMessages) int { // are used when sending a messages. We should fail with EINVAL when we find a // non-sendable control messages (such as IP_RECVERR). And the function should // be renamed to reflect that. -func Parse(t *kernel.Task, socketOrEndpoint interface{}, buf []byte, width uint) (socket.ControlMessages, error) { +func Parse(t *kernel.Task, socketOrEndpoint any, buf []byte, width uint) (socket.ControlMessages, error) { var ( cmsgs socket.ControlMessages fds []primitive.Int32 @@ -722,7 +722,7 @@ func Parse(t *kernel.Task, socketOrEndpoint interface{}, buf []byte, width uint) return cmsgs, nil } -func makeCreds(t *kernel.Task, socketOrEndpoint interface{}) SCMCredentials { +func makeCreds(t *kernel.Task, socketOrEndpoint any) SCMCredentials { if t == nil || socketOrEndpoint == nil { return nil } @@ -744,7 +744,7 @@ func MakeCreds(t *kernel.Task) SCMCredentials { // LINT.IfChange // New creates default control messages if needed. -func New(t *kernel.Task, socketOrEndpoint interface{}, rights SCMRights) transport.ControlMessages { +func New(t *kernel.Task, socketOrEndpoint any, rights SCMRights) transport.ControlMessages { return transport.ControlMessages{ Credentials: makeCreds(t, socketOrEndpoint), Rights: rights, diff --git a/pkg/sentry/socket/hostinet/stack.go b/pkg/sentry/socket/hostinet/stack.go index f64827bd6..3dc2b380b 100644 --- a/pkg/sentry/socket/hostinet/stack.go +++ b/pkg/sentry/socket/hostinet/stack.go @@ -417,13 +417,13 @@ func getLine(f *os.File, prefix string, withHeader bool) string { return "" } -func toSlice(i interface{}) []uint64 { +func toSlice(i any) []uint64 { v := reflect.Indirect(reflect.ValueOf(i)) return v.Slice(0, v.Len()).Interface().([]uint64) } // Statistics implements inet.Stack.Statistics. -func (s *Stack) Statistics(stat interface{}, arg string) error { +func (s *Stack) Statistics(stat any, arg string) error { var ( snmpTCP bool rawLine string diff --git a/pkg/sentry/socket/netfilter/netfilter.go b/pkg/sentry/socket/netfilter/netfilter.go index e4c06bdcb..278f07b72 100644 --- a/pkg/sentry/socket/netfilter/netfilter.go +++ b/pkg/sentry/socket/netfilter/netfilter.go @@ -37,7 +37,7 @@ import ( const enableLogging = false // nflog logs messages related to the writing and reading of iptables. -func nflog(format string, args ...interface{}) { +func nflog(format string, args ...any) { if enableLogging && log.IsLogging(log.Debug) { log.Debugf("netfilter: "+format, args...) } diff --git a/pkg/sentry/socket/netstack/stack.go b/pkg/sentry/socket/netstack/stack.go index bf2b0741a..cdbd761fd 100644 --- a/pkg/sentry/socket/netstack/stack.go +++ b/pkg/sentry/socket/netstack/stack.go @@ -280,7 +280,7 @@ func (s *Stack) SetTCPRecovery(recovery inet.TCPLossRecovery) error { } // Statistics implements inet.Stack.Statistics. -func (s *Stack) Statistics(stat interface{}, arg string) error { +func (s *Stack) Statistics(stat any, arg string) error { switch stats := stat.(type) { case *inet.StatDev: for _, ni := range s.Stack.NICInfo() { diff --git a/pkg/sentry/socket/unix/transport/unix.go b/pkg/sentry/socket/unix/transport/unix.go index 4234da73a..2e3135069 100644 --- a/pkg/sentry/socket/unix/transport/unix.go +++ b/pkg/sentry/socket/unix/transport/unix.go @@ -1028,7 +1028,7 @@ type stackHandler struct { } // Option implements tcpip.StackHandler. -func (h *stackHandler) Option(option interface{}) tcpip.Error { +func (h *stackHandler) Option(option any) tcpip.Error { panic("unimplemented") } diff --git a/pkg/sentry/strace/strace.go b/pkg/sentry/strace/strace.go index b5c6610f3..fa311f1f2 100644 --- a/pkg/sentry/strace/strace.go +++ b/pkg/sentry/strace/strace.go @@ -672,7 +672,7 @@ type syscallContext struct { // SyscallEnter implements kernel.Stracer.SyscallEnter. It logs the syscall // entry trace. -func (s SyscallMap) SyscallEnter(t *kernel.Task, sysno uintptr, args arch.SyscallArguments, flags uint32) interface{} { +func (s SyscallMap) SyscallEnter(t *kernel.Task, sysno uintptr, args arch.SyscallArguments, flags uint32) any { info, ok := s[sysno] if !ok { info = SyscallInfo{ @@ -701,7 +701,7 @@ func (s SyscallMap) SyscallEnter(t *kernel.Task, sysno uintptr, args arch.Syscal // SyscallExit implements kernel.Stracer.SyscallExit. It logs the syscall // exit trace. -func (s SyscallMap) SyscallExit(context interface{}, t *kernel.Task, sysno, rval uintptr, err error) { +func (s SyscallMap) SyscallExit(context any, t *kernel.Task, sysno, rval uintptr, err error) { errno := kernel.ExtractErrno(err, int(sysno)) c := context.(*syscallContext) diff --git a/pkg/sentry/syscalls/linux/sys_aio.go b/pkg/sentry/syscalls/linux/sys_aio.go index 7ed00cd7d..3a7a77295 100644 --- a/pkg/sentry/syscalls/linux/sys_aio.go +++ b/pkg/sentry/syscalls/linux/sys_aio.go @@ -123,7 +123,7 @@ func IoGetevents(t *kernel.Task, args arch.SyscallArguments) (uintptr, *kernel.S // Loop over all requests. for count := int32(0); count < events; count++ { // Get a request, per semantics. - var v interface{} + var v any if count >= minEvents { var ok bool v, ok = ctx.PopRequest() @@ -160,7 +160,7 @@ func IoGetevents(t *kernel.Task, args arch.SyscallArguments) (uintptr, *kernel.S return uintptr(events), nil, nil } -func waitForRequest(ctx *mm.AIOContext, t *kernel.Task, haveDeadline bool, deadline ktime.Time) (interface{}, error) { +func waitForRequest(ctx *mm.AIOContext, t *kernel.Task, haveDeadline bool, deadline ktime.Time) (any, error) { for { if v, ok := ctx.PopRequest(); ok { // Request was readily available. Just return it. diff --git a/pkg/sentry/syscalls/linux/sys_file.go b/pkg/sentry/syscalls/linux/sys_file.go index 1c4210cc8..42c0ec50d 100644 --- a/pkg/sentry/syscalls/linux/sys_file.go +++ b/pkg/sentry/syscalls/linux/sys_file.go @@ -508,7 +508,7 @@ type accessContext struct { } // Value implements context.Context. -func (ac accessContext) Value(key interface{}) interface{} { +func (ac accessContext) Value(key any) any { switch key { case auth.CtxCredentials: return ac.creds diff --git a/pkg/sentry/syscalls/linux/vfs2/getdents.go b/pkg/sentry/syscalls/linux/vfs2/getdents.go index 7eb20e180..08e47abde 100644 --- a/pkg/sentry/syscalls/linux/vfs2/getdents.go +++ b/pkg/sentry/syscalls/linux/vfs2/getdents.go @@ -89,7 +89,7 @@ type getdentsCallback struct { } var getdentsCallbackPool = sync.Pool{ - New: func() interface{} { + New: func() any { return &getdentsCallback{} }, } diff --git a/pkg/sentry/time/calibrated_clock.go b/pkg/sentry/time/calibrated_clock.go index eed74f6bd..aa4128a70 100644 --- a/pkg/sentry/time/calibrated_clock.go +++ b/pkg/sentry/time/calibrated_clock.go @@ -58,27 +58,27 @@ func NewCalibratedClock(c ClockID) *CalibratedClock { } // Debugf logs at debug level. -func (c *CalibratedClock) Debugf(format string, v ...interface{}) { +func (c *CalibratedClock) Debugf(format string, v ...any) { if log.IsLogging(log.Debug) { - args := []interface{}{c.ref.clockID} + args := []any{c.ref.clockID} args = append(args, v...) log.Debugf("CalibratedClock(%v): "+format, args...) } } // Infof logs at debug level. -func (c *CalibratedClock) Infof(format string, v ...interface{}) { +func (c *CalibratedClock) Infof(format string, v ...any) { if log.IsLogging(log.Info) { - args := []interface{}{c.ref.clockID} + args := []any{c.ref.clockID} args = append(args, v...) log.Infof("CalibratedClock(%v): "+format, args...) } } // Warningf logs at debug level. -func (c *CalibratedClock) Warningf(format string, v ...interface{}) { +func (c *CalibratedClock) Warningf(format string, v ...any) { if log.IsLogging(log.Warning) { - args := []interface{}{c.ref.clockID} + args := []any{c.ref.clockID} args = append(args, v...) log.Warningf("CalibratedClock(%v): "+format, args...) } @@ -86,14 +86,14 @@ func (c *CalibratedClock) Warningf(format string, v ...interface{}) { // reset forces the clock to restart the calibration process, logging the // passed message. -func (c *CalibratedClock) reset(str string, v ...interface{}) { +func (c *CalibratedClock) reset(str string, v ...any) { c.mu.Lock() defer c.mu.Unlock() c.resetLocked(str, v...) } // resetLocked is equivalent to reset with c.mu already held for writing. -func (c *CalibratedClock) resetLocked(str string, v ...interface{}) { +func (c *CalibratedClock) resetLocked(str string, v ...any) { c.Warningf(str+" Resetting clock; time may jump.", v...) c.ready = false c.ref.Reset() diff --git a/pkg/sentry/vfs/context.go b/pkg/sentry/vfs/context.go index 97018651f..70a78872c 100644 --- a/pkg/sentry/vfs/context.go +++ b/pkg/sentry/vfs/context.go @@ -46,7 +46,7 @@ type mountNamespaceContext struct { } // Value implements Context.Value. -func (mc mountNamespaceContext) Value(key interface{}) interface{} { +func (mc mountNamespaceContext) Value(key any) any { switch key { case CtxMountNamespace: mc.mntns.IncRef() @@ -88,7 +88,7 @@ func WithRoot(ctx context.Context, root VirtualDentry) context.Context { } // Value implements Context.Value. -func (rc rootContext) Value(key interface{}) interface{} { +func (rc rootContext) Value(key any) any { switch key { case CtxRoot: rc.root.IncRef() diff --git a/pkg/sentry/vfs/filesystem_type.go b/pkg/sentry/vfs/filesystem_type.go index aedb26bbb..583de11ff 100644 --- a/pkg/sentry/vfs/filesystem_type.go +++ b/pkg/sentry/vfs/filesystem_type.go @@ -48,7 +48,7 @@ type GetFilesystemOptions struct { // InternalData holds opaque FilesystemType-specific data. There is // intentionally no way for applications to specify InternalData; if it is // not nil, the call to GetFilesystem originates from within the sentry. - InternalData interface{} + InternalData any } // +stateify savable diff --git a/pkg/sentry/vfs/pathname.go b/pkg/sentry/vfs/pathname.go index 66d385973..7efe72021 100644 --- a/pkg/sentry/vfs/pathname.go +++ b/pkg/sentry/vfs/pathname.go @@ -22,7 +22,7 @@ import ( ) var fspathBuilderPool = sync.Pool{ - New: func() interface{} { + New: func() any { return &fspath.Builder{} }, } diff --git a/pkg/sentry/vfs/resolving_path.go b/pkg/sentry/vfs/resolving_path.go index 128c66fcf..169b80aed 100644 --- a/pkg/sentry/vfs/resolving_path.go +++ b/pkg/sentry/vfs/resolving_path.go @@ -107,7 +107,7 @@ func (resolveAbsSymlinkError) Error() string { } var resolvingPathPool = sync.Pool{ - New: func() interface{} { + New: func() any { return &ResolvingPath{} }, } diff --git a/pkg/sentry/watchdog/watchdog.go b/pkg/sentry/watchdog/watchdog.go index cabe58b93..6f15a30b5 100644 --- a/pkg/sentry/watchdog/watchdog.go +++ b/pkg/sentry/watchdog/watchdog.go @@ -104,7 +104,7 @@ func (a *Action) Set(v string) error { } // Get implements flag.Value. -func (a *Action) Get() interface{} { +func (a *Action) Get() any { return *a } diff --git a/pkg/shim/epoll.go b/pkg/shim/epoll.go index 5d29c8e28..fecd110c7 100644 --- a/pkg/shim/epoll.go +++ b/pkg/shim/epoll.go @@ -81,7 +81,7 @@ func (e *epoller) run(ctx context.Context) { } } -func (e *epoller) add(id string, cgx interface{}) error { +func (e *epoller) add(id string, cgx any) error { e.mu.Lock() defer e.mu.Unlock() cg, ok := cgx.(cgroups.Cgroup) diff --git a/pkg/shim/oom_v2.go b/pkg/shim/oom_v2.go index ed7791b57..b559278b9 100644 --- a/pkg/shim/oom_v2.go +++ b/pkg/shim/oom_v2.go @@ -86,7 +86,7 @@ func (w *watcherV2) run(ctx context.Context) { } // Add cgroups.Cgroup to the epoll monitor -func (w *watcherV2) add(id string, cgx interface{}) error { +func (w *watcherV2) add(id string, cgx any) error { cg, ok := cgx.(*cgroupsv2.Manager) if !ok { return fmt.Errorf("expected *cgroupsv2.Manager, got: %T", cgx) diff --git a/pkg/shim/proc/io.go b/pkg/shim/proc/io.go index 65f35ad62..6aa588310 100644 --- a/pkg/shim/proc/io.go +++ b/pkg/shim/proc/io.go @@ -32,7 +32,7 @@ import ( // TODO(random-liu): This file can be a util. var bufPool = sync.Pool{ - New: func() interface{} { + New: func() any { buffer := make([]byte, 32<<10) return &buffer }, diff --git a/pkg/shim/runsc/utils.go b/pkg/shim/runsc/utils.go index 8af17de29..bf7d58fe1 100644 --- a/pkg/shim/runsc/utils.go +++ b/pkg/shim/runsc/utils.go @@ -22,7 +22,7 @@ import ( ) var bytesBufferPool = sync.Pool{ - New: func() interface{} { + New: func() any { return bytes.NewBuffer(nil) }, } diff --git a/pkg/shim/service.go b/pkg/shim/service.go index ac55a4963..35d969d3a 100644 --- a/pkg/shim/service.go +++ b/pkg/shim/service.go @@ -62,7 +62,7 @@ import ( var ( empty = &types.Empty{} bufPool = sync.Pool{ - New: func() interface{} { + New: func() any { buffer := make([]byte, 32<<10) return &buffer }, @@ -85,7 +85,7 @@ type oomPoller interface { io.Closer // add adds `cg` cgroup to oom poller. `cg` is cgroups.Cgroup in v1 and // `cgroupsv2.Manager` in v2 - add(id string, cg interface{}) error + add(id string, cg any) error // run monitors oom event and notifies the shim about them run(ctx context.Context) } @@ -113,7 +113,7 @@ func New(ctx context.Context, id string, publisher shim.Publisher, cancel func() s := &service{ id: id, processes: make(map[string]process.Process), - events: make(chan interface{}, 128), + events: make(chan any, 128), ec: proc.ExitCh, oomPoller: ep, cancel: cancel, @@ -160,7 +160,7 @@ type service struct { // processes maps ExecId to processes running through exec. processes map[string]process.Process - events chan interface{} + events chan any // platform handles operations related to the console. platform stdio.Platform @@ -502,7 +502,7 @@ func (s *service) create(ctx context.Context, r *taskAPI.CreateTaskRequest) (*ta pid := process.Pid() if pid > 0 { var ( - cg interface{} + cg any err error ) if cgroups.Mode() == cgroups.Unified { @@ -1041,7 +1041,7 @@ func (s *service) getProcess(execID string) (process.Process, error) { return p, nil } -func getTopic(e interface{}) string { +func getTopic(e any) string { switch e.(type) { case *events.TaskCreate: return runtime.TaskCreateEventTopic diff --git a/pkg/state/state.go b/pkg/state/state.go index ff4b30c36..4a9e6eadf 100644 --- a/pkg/state/state.go +++ b/pkg/state/state.go @@ -87,7 +87,7 @@ func (e *ErrState) Unwrap() error { } // Save saves the given object state. -func Save(ctx context.Context, w wire.Writer, rootPtr interface{}) (Stats, error) { +func Save(ctx context.Context, w wire.Writer, rootPtr any) (Stats, error) { // Create the encoding state. es := encodeState{ ctx: ctx, @@ -106,7 +106,7 @@ func Save(ctx context.Context, w wire.Writer, rootPtr interface{}) (Stats, error } // Load loads a checkpoint. -func Load(ctx context.Context, r wire.Reader, rootPtr interface{}) (Stats, error) { +func Load(ctx context.Context, r wire.Reader, rootPtr any) (Stats, error) { // Create the decoding state. ds := decodeState{ ctx: ctx, @@ -155,7 +155,7 @@ type Sink struct { // m.Load(0, &x.A) // Field is A. // m.Load(1, &x.B) // Field is B. // } -func (s Sink) Save(slot int, objPtr interface{}) { +func (s Sink) Save(slot int, objPtr any) { s.internal.save(slot, reflect.ValueOf(objPtr).Elem()) } @@ -171,11 +171,11 @@ func (s Sink) Save(slot int, objPtr interface{}) { // } // // func (x *X) StateLoad(m Source) { -// m.LoadValue(0, new(int64), func(x interface{}) { +// m.LoadValue(0, new(int64), func(x any) { // x.A = P.Foo(x.(int64)) // }) // } -func (s Sink) SaveValue(slot int, obj interface{}) { +func (s Sink) SaveValue(slot int, obj any) { s.internal.save(slot, reflect.ValueOf(obj)) } @@ -222,7 +222,7 @@ type Source struct { // Load loads the given object passed as a pointer.. // // See Sink.Save for an example. -func (s Source) Load(slot int, objPtr interface{}) { +func (s Source) Load(slot int, objPtr any) { s.internal.load(slot, reflect.ValueOf(objPtr), false, nil) } @@ -230,14 +230,14 @@ func (s Source) Load(slot int, objPtr interface{}) { // AfterLoad executions to complete prior to running this object's AfterLoad. // // See Sink.Save for an example. -func (s Source) LoadWait(slot int, objPtr interface{}) { +func (s Source) LoadWait(slot int, objPtr any) { s.internal.load(slot, reflect.ValueOf(objPtr), true, nil) } // LoadValue loads the given object value from the map. // // See Sink.SaveValue for an example. -func (s Source) LoadValue(slot int, objPtr interface{}, fn func(interface{})) { +func (s Source) LoadValue(slot int, objPtr any, fn func(any)) { o := reflect.ValueOf(objPtr) s.internal.load(slot, o, true, func() { fn(o.Elem().Interface()) }) } @@ -258,13 +258,13 @@ func (s Source) Context() context.Context { // IsZeroValue checks if the given value is the zero value. // // This function is used by the stateify tool. -func IsZeroValue(val interface{}) bool { +func IsZeroValue(val any) bool { return val == nil || reflect.ValueOf(val).Elem().IsZero() } // Failf is a wrapper around panic that should be used to generate errors that // can be caught during saving and loading. -func Failf(fmtStr string, v ...interface{}) { +func Failf(fmtStr string, v ...any) { panic(fmt.Errorf(fmtStr, v...)) } diff --git a/pkg/state/tests/array.go b/pkg/state/tests/array.go index 0972a80e7..c9a69787c 100644 --- a/pkg/state/tests/array.go +++ b/pkg/state/tests/array.go @@ -16,20 +16,20 @@ package tests // +stateify savable type arrayContainer struct { - v [1]interface{} + v [1]any } // +stateify savable type arrayPtrContainer struct { - v *[1]interface{} + v *[1]any } // +stateify savable type sliceContainer struct { - v []interface{} + v []any } // +stateify savable type slicePtrContainer struct { - v *[]interface{} + v *[]any } diff --git a/pkg/state/tests/array_test.go b/pkg/state/tests/array_test.go index a347b2947..67b771b34 100644 --- a/pkg/state/tests/array_test.go +++ b/pkg/state/tests/array_test.go @@ -19,7 +19,7 @@ import ( "testing" ) -var allArrayPrimitives = []interface{}{ +var allArrayPrimitives = []any{ [1]bool{}, [1]bool{true}, [2]bool{false, true}, @@ -71,12 +71,12 @@ func TestArrayPrimitives(t *testing.T) { func TestSlices(t *testing.T) { var allSlices = flatten( - filter(allArrayPrimitives, func(o interface{}) (interface{}, bool) { + filter(allArrayPrimitives, func(o any) (any, bool) { v := reflect.New(reflect.TypeOf(o)).Elem() v.Set(reflect.ValueOf(o)) return v.Slice(0, v.Len()).Interface(), true }), - filter(allArrayPrimitives, func(o interface{}) (interface{}, bool) { + filter(allArrayPrimitives, func(o any) (any, bool) { v := reflect.New(reflect.TypeOf(o)).Elem() v.Set(reflect.ValueOf(o)) if v.Len() == 0 { @@ -85,7 +85,7 @@ func TestSlices(t *testing.T) { } return v.Slice(1, v.Len()).Interface(), true }), - filter(allArrayPrimitives, func(o interface{}) (interface{}, bool) { + filter(allArrayPrimitives, func(o any) (any, bool) { v := reflect.New(reflect.TypeOf(o)).Elem() v.Set(reflect.ValueOf(o)) if v.Len() == 0 { @@ -103,11 +103,11 @@ func TestSlices(t *testing.T) { func TestArrayContainers(t *testing.T) { var ( - emptyArray [1]interface{} - fullArray [1]interface{} + emptyArray [1]any + fullArray [1]any ) fullArray[0] = &emptyArray - runTestCases(t, false, "", []interface{}{ + runTestCases(t, false, "", []any{ arrayContainer{v: emptyArray}, arrayContainer{v: fullArray}, arrayPtrContainer{v: nil}, @@ -118,11 +118,11 @@ func TestArrayContainers(t *testing.T) { func TestSliceContainers(t *testing.T) { var ( - nilSlice []interface{} - emptySlice = make([]interface{}, 0) - fullSlice = []interface{}{nil} + nilSlice []any + emptySlice = make([]any, 0) + fullSlice = []any{nil} ) - runTestCases(t, false, "", []interface{}{ + runTestCases(t, false, "", []any{ sliceContainer{v: nilSlice}, sliceContainer{v: emptySlice}, sliceContainer{v: fullSlice}, diff --git a/pkg/state/tests/bench_test.go b/pkg/state/tests/bench_test.go index 7e102c907..5e7fc6039 100644 --- a/pkg/state/tests/bench_test.go +++ b/pkg/state/tests/bench_test.go @@ -26,7 +26,7 @@ import ( ) // buildPtrObject builds a benchmark object. -func buildPtrObject(n int) interface{} { +func buildPtrObject(n int) any { b := new(benchStruct) for i := 0; i < n; i++ { b = &benchStruct{B: b} @@ -35,7 +35,7 @@ func buildPtrObject(n int) interface{} { } // buildMapObject builds a benchmark object. -func buildMapObject(n int) interface{} { +func buildMapObject(n int) any { b := new(benchStruct) m := make(map[int]*benchStruct) for i := 0; i < n; i++ { @@ -45,7 +45,7 @@ func buildMapObject(n int) interface{} { } // buildSliceObject builds a benchmark object. -func buildSliceObject(n int) interface{} { +func buildSliceObject(n int) any { b := new(benchStruct) s := make([]*benchStruct, 0, n) for i := 0; i < n; i++ { @@ -55,7 +55,7 @@ func buildSliceObject(n int) interface{} { } var allObjects = map[string]struct { - New func(int) interface{} + New func(int) any }{ "ptr": { New: buildPtrObject, @@ -68,7 +68,7 @@ var allObjects = map[string]struct { }, } -func buildObjects(n int, fn func(int) interface{}) (iters int, v interface{}) { +func buildObjects(n int, fn func(int) any) (iters int, v any) { // maxSize is the maximum size of an individual object below. For an N // larger than this, we start to return multiple objects. const maxSize = 1024 @@ -80,22 +80,22 @@ func buildObjects(n int, fn func(int) interface{}) (iters int, v interface{}) { } // gobSave is a version of save using gob (no stats available). -func gobSave(_ context.Context, w wire.Writer, v interface{}) (_ state.Stats, err error) { +func gobSave(_ context.Context, w wire.Writer, v any) (_ state.Stats, err error) { enc := gob.NewEncoder(w) err = enc.Encode(v) return } // gobLoad is a version of load using gob (no stats available). -func gobLoad(_ context.Context, r wire.Reader, v interface{}) (_ state.Stats, err error) { +func gobLoad(_ context.Context, r wire.Reader, v any) (_ state.Stats, err error) { dec := gob.NewDecoder(r) err = dec.Decode(v) return } var allAlgos = map[string]struct { - Save func(context.Context, wire.Writer, interface{}) (state.Stats, error) - Load func(context.Context, wire.Reader, interface{}) (state.Stats, error) + Save func(context.Context, wire.Writer, any) (state.Stats, error) + Load func(context.Context, wire.Reader, any) (state.Stats, error) MaxPtr int }{ "state": { diff --git a/pkg/state/tests/float_test.go b/pkg/state/tests/float_test.go index 3e89edd9c..e9ada6b59 100644 --- a/pkg/state/tests/float_test.go +++ b/pkg/state/tests/float_test.go @@ -62,27 +62,27 @@ func TestFloat(t *testing.T) { const onlyDouble float64 = 1.0000000000000002 func TestFloatTruncation(t *testing.T) { - runTestCases(t, true, "pass", []interface{}{ + runTestCases(t, true, "pass", []any{ truncatingFloat32{save: onlyDouble}, }) - runTestCases(t, false, "fail", []interface{}{ + runTestCases(t, false, "fail", []any{ truncatingFloat32{save: 1.0}, }) } -var safeComplex64s = combine(safeFloat32s, safeFloat32s, func(i, j interface{}) interface{} { +var safeComplex64s = combine(safeFloat32s, safeFloat32s, func(i, j any) any { return complex(i.(float32), j.(float32)) }) -var allComplex64s = combine(allFloat32s, allFloat32s, func(i, j interface{}) interface{} { +var allComplex64s = combine(allFloat32s, allFloat32s, func(i, j any) any { return complex(i.(float32), j.(float32)) }) -var safeComplex128s = combine(safeFloat64s, safeFloat64s, func(i, j interface{}) interface{} { +var safeComplex128s = combine(safeFloat64s, safeFloat64s, func(i, j any) any { return complex(i.(float64), j.(float64)) }) -var allComplex128s = combine(allFloat64s, allFloat64s, func(i, j interface{}) interface{} { +var allComplex128s = combine(allFloat64s, allFloat64s, func(i, j any) any { return complex(i.(float64), j.(float64)) }) @@ -107,12 +107,12 @@ func TestComplex(t *testing.T) { } func TestComplexTruncation(t *testing.T) { - runTestCases(t, true, "pass", []interface{}{ + runTestCases(t, true, "pass", []any{ truncatingComplex64{save: complex(onlyDouble, onlyDouble)}, truncatingComplex64{save: complex(1.0, onlyDouble)}, truncatingComplex64{save: complex(onlyDouble, 1.0)}, }) - runTestCases(t, false, "fail", []interface{}{ + runTestCases(t, false, "fail", []any{ truncatingComplex64{save: complex(1.0, 1.0)}, }) } diff --git a/pkg/state/tests/integer_test.go b/pkg/state/tests/integer_test.go index 2b1609af0..78977b490 100644 --- a/pkg/state/tests/integer_test.go +++ b/pkg/state/tests/integer_test.go @@ -58,7 +58,7 @@ func TestInt(t *testing.T) { } func TestIntTruncation(t *testing.T) { - runTestCases(t, true, "pass", []interface{}{ + runTestCases(t, true, "pass", []any{ truncatingInt8{save: math.MinInt8 - 1}, truncatingInt16{save: math.MinInt16 - 1}, truncatingInt32{save: math.MinInt32 - 1}, @@ -66,7 +66,7 @@ func TestIntTruncation(t *testing.T) { truncatingInt16{save: math.MaxInt16 + 1}, truncatingInt32{save: math.MaxInt32 + 1}, }) - runTestCases(t, false, "fail", []interface{}{ + runTestCases(t, false, "fail", []any{ truncatingInt8{save: 1}, truncatingInt16{save: 1}, truncatingInt32{save: 1}, @@ -81,12 +81,12 @@ func TestUint(t *testing.T) { } func TestUintTruncation(t *testing.T) { - runTestCases(t, true, "pass", []interface{}{ + runTestCases(t, true, "pass", []any{ truncatingUint8{save: math.MaxUint8 + 1}, truncatingUint16{save: math.MaxUint16 + 1}, truncatingUint32{save: math.MaxUint32 + 1}, }) - runTestCases(t, false, "fail", []interface{}{ + runTestCases(t, false, "fail", []any{ truncatingUint8{save: 1}, truncatingUint16{save: 1}, truncatingUint32{save: 1}, diff --git a/pkg/state/tests/load.go b/pkg/state/tests/load.go index a8350c0f3..0023948a9 100644 --- a/pkg/state/tests/load.go +++ b/pkg/state/tests/load.go @@ -16,7 +16,7 @@ package tests // +stateify savable type genericContainer struct { - v interface{} + v any } // +stateify savable diff --git a/pkg/state/tests/load_test.go b/pkg/state/tests/load_test.go index 3c73ac391..2e835520f 100644 --- a/pkg/state/tests/load_test.go +++ b/pkg/state/tests/load_test.go @@ -19,23 +19,23 @@ import ( ) func TestLoadHooks(t *testing.T) { - runTestCases(t, false, "load-hooks", []interface{}{ + runTestCases(t, false, "load-hooks", []any{ // Root object being a struct. afterLoadStruct{v: 1}, valueLoadStruct{v: 1}, genericContainer{v: &afterLoadStruct{v: 1}}, genericContainer{v: &valueLoadStruct{v: 1}}, - sliceContainer{v: []interface{}{&afterLoadStruct{v: 1}}}, - sliceContainer{v: []interface{}{&valueLoadStruct{v: 1}}}, + sliceContainer{v: []any{&afterLoadStruct{v: 1}}}, + sliceContainer{v: []any{&valueLoadStruct{v: 1}}}, // Root object being a pointer. &afterLoadStruct{v: 1}, &valueLoadStruct{v: 1}, &genericContainer{v: &afterLoadStruct{v: 1}}, &genericContainer{v: &valueLoadStruct{v: 1}}, - &sliceContainer{v: []interface{}{&afterLoadStruct{v: 1}}}, - &sliceContainer{v: []interface{}{&valueLoadStruct{v: 1}}}, - &mapContainer{v: map[int]interface{}{0: &afterLoadStruct{v: 1}}}, - &mapContainer{v: map[int]interface{}{0: &valueLoadStruct{v: 1}}}, + &sliceContainer{v: []any{&afterLoadStruct{v: 1}}}, + &sliceContainer{v: []any{&valueLoadStruct{v: 1}}}, + &mapContainer{v: map[int]any{0: &afterLoadStruct{v: 1}}}, + &mapContainer{v: map[int]any{0: &valueLoadStruct{v: 1}}}, }) } @@ -50,7 +50,7 @@ func TestCycles(t *testing.T) { cs1.c = &cs2 cs2.c = &cs1 - runTestCases(t, false, "cycles", []interface{}{ + runTestCases(t, false, "cycles", []any{ cs, cs1, }) @@ -62,7 +62,7 @@ func TestDeadlock(t *testing.T) { bs := badCycleStruct{nil} bs.b = &bs - runTestCases(t, false, "self", []interface{}{ + runTestCases(t, false, "self", []any{ &bs, }) @@ -72,7 +72,7 @@ func TestDeadlock(t *testing.T) { bs1.b = &bs2 bs2.b = &bs1 - runTestCases(t, true, "deadlock", []interface{}{ + runTestCases(t, true, "deadlock", []any{ &bs1, }) } diff --git a/pkg/state/tests/map.go b/pkg/state/tests/map.go index db4e548f1..d30ed59b3 100644 --- a/pkg/state/tests/map.go +++ b/pkg/state/tests/map.go @@ -16,12 +16,12 @@ package tests // +stateify savable type mapContainer struct { - v map[int]interface{} + v map[int]any } // +stateify savable type mapPtrContainer struct { - v *map[int]interface{} + v *map[int]any } // +stateify savable diff --git a/pkg/state/tests/map_test.go b/pkg/state/tests/map_test.go index 92bf0fc01..e5a5b6414 100644 --- a/pkg/state/tests/map_test.go +++ b/pkg/state/tests/map_test.go @@ -19,7 +19,7 @@ import ( "testing" ) -var allMapPrimitives = []interface{}{ +var allMapPrimitives = []any{ bool(true), int(1), int8(1), @@ -40,12 +40,12 @@ var allMapKeys = flatten(allMapPrimitives, pointersTo(allMapPrimitives)) var allMapValues = flatten(allMapPrimitives, pointersTo(allMapPrimitives), interfacesTo(allMapPrimitives)) -var emptyMaps = combine(allMapKeys, allMapValues, func(v1, v2 interface{}) interface{} { +var emptyMaps = combine(allMapKeys, allMapValues, func(v1, v2 any) any { m := reflect.MakeMap(reflect.MapOf(reflect.TypeOf(v1), reflect.TypeOf(v2))) return m.Interface() }) -var fullMaps = combine(allMapKeys, allMapValues, func(v1, v2 interface{}) interface{} { +var fullMaps = combine(allMapKeys, allMapValues, func(v1, v2 any) any { m := reflect.MakeMap(reflect.MapOf(reflect.TypeOf(v1), reflect.TypeOf(v2))) m.SetMapIndex(reflect.Zero(reflect.TypeOf(v1)), reflect.Zero(reflect.TypeOf(v2))) return m.Interface() @@ -55,7 +55,7 @@ func TestMapAliasing(t *testing.T) { v := make(map[int]int) ptrToV := &v aliases := []map[int]int{v, v} - runTestCases(t, false, "", []interface{}{ptrToV, aliases}) + runTestCases(t, false, "", []any{ptrToV, aliases}) } func TestMapsEmpty(t *testing.T) { @@ -74,11 +74,11 @@ func TestMapsFull(t *testing.T) { func TestMapContainers(t *testing.T) { var ( - nilMap map[int]interface{} - emptyMap = make(map[int]interface{}) - fullMap = map[int]interface{}{0: nil} + nilMap map[int]any + emptyMap = make(map[int]any) + fullMap = map[int]any{0: nil} ) - runTestCases(t, false, "", []interface{}{ + runTestCases(t, false, "", []any{ mapContainer{v: nilMap}, mapContainer{v: emptyMap}, mapContainer{v: fullMap}, diff --git a/pkg/state/tests/struct.go b/pkg/state/tests/struct.go index 69143d194..0726249dd 100644 --- a/pkg/state/tests/struct.go +++ b/pkg/state/tests/struct.go @@ -88,13 +88,13 @@ func (ifv *innerFieldValue) loadV(sfv *savedFieldValue) { // +stateify savable type system struct { - v1 interface{} - v2 interface{} + v1 any + v2 any } // +stateify savable type system3 struct { - v1 interface{} - v2 interface{} - v3 interface{} + v1 any + v2 any + v3 any } diff --git a/pkg/state/tests/struct_test.go b/pkg/state/tests/struct_test.go index 9826f1ee9..b8277a87e 100644 --- a/pkg/state/tests/struct_test.go +++ b/pkg/state/tests/struct_test.go @@ -20,36 +20,36 @@ import ( ) func TestEmptyStruct(t *testing.T) { - runTestCases(t, false, "plain", []interface{}{ + runTestCases(t, false, "plain", []any{ unregisteredEmptyStruct{}, typeOnlyEmptyStruct{}, savableEmptyStruct{}, }) - runTestCases(t, false, "pointers", pointersTo([]interface{}{ + runTestCases(t, false, "pointers", pointersTo([]any{ unregisteredEmptyStruct{}, typeOnlyEmptyStruct{}, savableEmptyStruct{}, })) - runTestCases(t, false, "interfaces-pass", interfacesTo([]interface{}{ + runTestCases(t, false, "interfaces-pass", interfacesTo([]any{ // Only registered types can be dispatched via interfaces. All // other types should fail, even if it is the empty struct. savableEmptyStruct{}, })) - runTestCases(t, true, "interfaces-fail", interfacesTo([]interface{}{ + runTestCases(t, true, "interfaces-fail", interfacesTo([]any{ unregisteredEmptyStruct{}, typeOnlyEmptyStruct{}, })) - runTestCases(t, false, "interfacesToPointers-pass", interfacesTo(pointersTo([]interface{}{ + runTestCases(t, false, "interfacesToPointers-pass", interfacesTo(pointersTo([]any{ savableEmptyStruct{}, }))) - runTestCases(t, true, "interfacesToPointers-fail", interfacesTo(pointersTo([]interface{}{ + runTestCases(t, true, "interfacesToPointers-fail", interfacesTo(pointersTo([]any{ unregisteredEmptyStruct{}, typeOnlyEmptyStruct{}, }))) // Ensuring empty struct aliasing works. es := emptyStructPointer{new(struct{})} - runTestCases(t, false, "empty-struct-pointers", []interface{}{ + runTestCases(t, false, "empty-struct-pointers", []any{ emptyStructPointer{}, es, []emptyStructPointer{es, es}, // Same pointer. @@ -75,7 +75,7 @@ func TestEmbeddedPointers(t *testing.T) { osl := outerSlice{oa.inner[:]} ofv := outerFieldValue{innerFieldValue{magic()}} - runTestCases(t, false, "embedded-pointers", []interface{}{ + runTestCases(t, false, "embedded-pointers", []any{ system{&ofs, &ofs.inner}, system{&ofs.inner, &ofs}, system{&of1, &of1.inner}, diff --git a/pkg/state/tests/tests.go b/pkg/state/tests/tests.go index 435a0e9db..c1d5e3849 100644 --- a/pkg/state/tests/tests.go +++ b/pkg/state/tests/tests.go @@ -40,7 +40,7 @@ func (discard) WriteByte(byte) error { return nil } // // N.B. This only handles one level of dereferences for NaN. Otherwise we // would need to fork the entire implementation of reflect.DeepEqual. -func checkEqual(root, loadedValue interface{}) bool { +func checkEqual(root, loadedValue any) bool { if reflect.DeepEqual(root, loadedValue) { return true } @@ -74,7 +74,7 @@ func checkEqual(root, loadedValue interface{}) bool { } // runTestCases runs a test for each object in objects. -func runTestCases(t *testing.T, shouldFail bool, prefix string, objects []interface{}) { +func runTestCases(t *testing.T, shouldFail bool, prefix string, objects []any) { t.Helper() for i, root := range objects { t.Run(fmt.Sprintf("%s%d", prefix, i), func(t *testing.T) { @@ -154,8 +154,8 @@ func runTestCases(t *testing.T, shouldFail bool, prefix string, objects []interf } } -// convert converts the slice to an []interface{}. -func convert(v interface{}) (r []interface{}) { +// convert converts the slice to an []any. +func convert(v any) (r []any) { s := reflect.ValueOf(v) // Must be slice. for i := 0; i < s.Len(); i++ { r = append(r, s.Index(i).Interface()) @@ -164,7 +164,7 @@ func convert(v interface{}) (r []interface{}) { } // flatten flattens multiple slices. -func flatten(vs ...interface{}) (r []interface{}) { +func flatten(vs ...any) (r []any) { for _, v := range vs { r = append(r, convert(v)...) } @@ -172,7 +172,7 @@ func flatten(vs ...interface{}) (r []interface{}) { } // filter maps from one slice to another. -func filter(vs interface{}, fn func(interface{}) (interface{}, bool)) (r []interface{}) { +func filter(vs any, fn func(any) (any, bool)) (r []any) { s := reflect.ValueOf(vs) for i := 0; i < s.Len(); i++ { v, ok := fn(s.Index(i).Interface()) @@ -184,7 +184,7 @@ func filter(vs interface{}, fn func(interface{}) (interface{}, bool)) (r []inter } // combine combines objects in two slices as specified. -func combine(v1, v2 interface{}, fn func(_, _ interface{}) interface{}) (r []interface{}) { +func combine(v1, v2 any, fn func(_, _ any) any) (r []any) { s1 := reflect.ValueOf(v1) s2 := reflect.ValueOf(v2) for i := 0; i < s1.Len(); i++ { @@ -197,8 +197,8 @@ func combine(v1, v2 interface{}, fn func(_, _ interface{}) interface{}) (r []int } // pointersTo is a filter function that returns pointers. -func pointersTo(vs interface{}) []interface{} { - return filter(vs, func(o interface{}) (interface{}, bool) { +func pointersTo(vs any) []any { + return filter(vs, func(o any) (any, bool) { v := reflect.New(reflect.TypeOf(o)) v.Elem().Set(reflect.ValueOf(o)) return v.Interface(), true @@ -206,9 +206,9 @@ func pointersTo(vs interface{}) []interface{} { } // interfacesTo is a filter function that returns interface objects. -func interfacesTo(vs interface{}) []interface{} { - return filter(vs, func(o interface{}) (interface{}, bool) { - var v [1]interface{} +func interfacesTo(vs any) []any { + return filter(vs, func(o any) (any, bool) { + var v [1]any v[0] = o return v, true }) diff --git a/pkg/state/types.go b/pkg/state/types.go index 420675880..8df2ac64a 100644 --- a/pkg/state/types.go +++ b/pkg/state/types.go @@ -180,7 +180,7 @@ func (tbd *typeDecodeDatabase) LookupType(id typeID) reflect.Type { typ, ok = primitiveTypeDatabase[name] if !ok && name == interfaceType { // Matches the built-in interface type. - var i interface{} + var i any return reflect.TypeOf(&i).Elem() } if !ok { diff --git a/pkg/sync/checklocks_on_unsafe.go b/pkg/sync/checklocks_on_unsafe.go index f2bfde083..16a5d3fba 100644 --- a/pkg/sync/checklocks_on_unsafe.go +++ b/pkg/sync/checklocks_on_unsafe.go @@ -87,7 +87,7 @@ func noteUnlock(l unsafe.Pointer) { func dumpLocks() string { var s strings.Builder - locksHeld.Range(func(key, value interface{}) bool { + locksHeld.Range(func(key, value any) bool { goid := key.(int64) locks := value.(*gLocks) diff --git a/pkg/sync/runtime_unsafe.go b/pkg/sync/runtime_unsafe.go index fc3241c5d..4aaba74f6 100644 --- a/pkg/sync/runtime_unsafe.go +++ b/pkg/sync/runtime_unsafe.go @@ -116,7 +116,7 @@ func RandUintptr() uintptr { // MapKeyHasher returns a hash function for pointers of m's key type. // // Preconditions: m must be a map. -func MapKeyHasher(m interface{}) func(unsafe.Pointer, uintptr) uintptr { +func MapKeyHasher(m any) func(unsafe.Pointer, uintptr) uintptr { if rtyp := reflect.TypeOf(m); rtyp.Kind() != reflect.Map { panic(fmt.Sprintf("sync.MapKeyHasher: m is %v, not map", rtyp)) } diff --git a/pkg/syncevent/waiter_test.go b/pkg/syncevent/waiter_test.go index 8bfeda13d..26a092741 100644 --- a/pkg/syncevent/waiter_test.go +++ b/pkg/syncevent/waiter_test.go @@ -190,7 +190,7 @@ func BenchmarkSleeperMultiNotifyWaitAck(b *testing.B) { // The sleep package doesn't provide sync.Pool allocation of Wakers; // we do for a fairer comparison. wakerPool := sync.Pool{ - New: func() interface{} { + New: func() any { return &sleep.Waker{} }, } @@ -229,7 +229,7 @@ func BenchmarkSleeperTempNotifyWaitAck(b *testing.B) { // The sleep package doesn't provide sync.Pool allocation of Sleepers; // we do for a fairer comparison. sleeperPool := sync.Pool{ - New: func() interface{} { + New: func() any { return &sleep.Sleeper{} }, } diff --git a/pkg/syncevent/waiter_unsafe.go b/pkg/syncevent/waiter_unsafe.go index 0b6059248..7c6b1b19f 100644 --- a/pkg/syncevent/waiter_unsafe.go +++ b/pkg/syncevent/waiter_unsafe.go @@ -174,7 +174,7 @@ func (w *Waiter) NotifyPending() { } var waiterPool = sync.Pool{ - New: func() interface{} { + New: func() any { w := &Waiter{} w.Init() return w diff --git a/pkg/tcpip/faketime/faketime.go b/pkg/tcpip/faketime/faketime.go index 9f8f51647..41a2040a8 100644 --- a/pkg/tcpip/faketime/faketime.go +++ b/pkg/tcpip/faketime/faketime.go @@ -354,11 +354,11 @@ func (h timeHeap) Swap(i, j int) { h[i], h[j] = h[j], h[i] } -func (h *timeHeap) Push(x interface{}) { +func (h *timeHeap) Push(x any) { *h = append(*h, x.(time.Time)) } -func (h *timeHeap) Pop() interface{} { +func (h *timeHeap) Pop() any { last := (*h)[len(*h)-1] *h = (*h)[:len(*h)-1] return last diff --git a/pkg/tcpip/socketops.go b/pkg/tcpip/socketops.go index b7dbe45c8..28d04ba26 100644 --- a/pkg/tcpip/socketops.go +++ b/pkg/tcpip/socketops.go @@ -116,7 +116,7 @@ func (*DefaultSocketOptionsHandler) OnSetReceiveBufferSize(v, oldSz int64) (newS // implemented by the stack. type StackHandler interface { // Option allows retrieving stack wide options. - Option(option interface{}) Error + Option(option any) Error // TransportProtocolOption allows retrieving individual protocol level // option values. diff --git a/pkg/tcpip/stack/packet_buffer.go b/pkg/tcpip/stack/packet_buffer.go index 3f80093a2..f718d40ad 100644 --- a/pkg/tcpip/stack/packet_buffer.go +++ b/pkg/tcpip/stack/packet_buffer.go @@ -34,7 +34,7 @@ const ( ) var pkPool = sync.Pool{ - New: func() interface{} { + New: func() any { return &packetBuffer{} }, } diff --git a/pkg/tcpip/stack/stack.go b/pkg/tcpip/stack/stack.go index 855df2a78..a6ce8fa2b 100644 --- a/pkg/tcpip/stack/stack.go +++ b/pkg/tcpip/stack/stack.go @@ -790,7 +790,7 @@ func (s *Stack) NewPacketEndpoint(cooked bool, netProto tcpip.NetworkProtocolNum } // NICContext is an opaque pointer used to store client-supplied NIC metadata. -type NICContext interface{} +type NICContext any // NICOptions specifies the configuration of a NIC as it is being created. // The zero value creates an enabled, unnamed NIC. diff --git a/pkg/tcpip/stack/stack_options.go b/pkg/tcpip/stack/stack_options.go index 80e8e0089..57af874a7 100644 --- a/pkg/tcpip/stack/stack_options.go +++ b/pkg/tcpip/stack/stack_options.go @@ -50,7 +50,7 @@ type ReceiveBufferSizeOption struct { type TCPInvalidRateLimitOption time.Duration // SetOption allows setting stack wide options. -func (s *Stack) SetOption(option interface{}) tcpip.Error { +func (s *Stack) SetOption(option any) tcpip.Error { switch v := option.(type) { case tcpip.SendBufferSizeOption: // Make sure we don't allow lowering the buffer below minimum @@ -99,7 +99,7 @@ func (s *Stack) SetOption(option interface{}) tcpip.Error { } // Option allows retrieving stack wide options. -func (s *Stack) Option(option interface{}) tcpip.Error { +func (s *Stack) Option(option any) tcpip.Error { switch v := option.(type) { case *tcpip.SendBufferSizeOption: s.mu.RLock() diff --git a/pkg/tcpip/transport/tcp/connect.go b/pkg/tcpip/transport/tcp/connect.go index b6c3c768f..451f2cef1 100644 --- a/pkg/tcpip/transport/tcp/connect.go +++ b/pkg/tcpip/transport/tcp/connect.go @@ -711,7 +711,7 @@ func parseSynSegmentOptions(s *segment) header.TCPSynOptions { } var optionPool = sync.Pool{ - New: func() interface{} { + New: func() any { return &[maxOptionSize]byte{} }, } diff --git a/pkg/tcpip/transport/tcp/segment.go b/pkg/tcpip/transport/tcp/segment.go index 1655a17dd..1bb3a490b 100644 --- a/pkg/tcpip/transport/tcp/segment.go +++ b/pkg/tcpip/transport/tcp/segment.go @@ -41,7 +41,7 @@ const ( ) var segmentPool = sync.Pool{ - New: func() interface{} { + New: func() any { return &segment{} }, } diff --git a/pkg/tcpip/transport/tcp/segment_heap.go b/pkg/tcpip/transport/tcp/segment_heap.go index 8d3ddce4b..33dcc090a 100644 --- a/pkg/tcpip/transport/tcp/segment_heap.go +++ b/pkg/tcpip/transport/tcp/segment_heap.go @@ -36,12 +36,12 @@ func (h *segmentHeap) Swap(i, j int) { } // Push adds x as the last element of h. -func (h *segmentHeap) Push(x interface{}) { +func (h *segmentHeap) Push(x any) { *h = append(*h, x.(*segment)) } // Pop removes the last element of h and returns it. -func (h *segmentHeap) Pop() interface{} { +func (h *segmentHeap) Pop() any { old := *h n := len(old) x := old[n-1] diff --git a/pkg/test/dockerutil/dockerutil.go b/pkg/test/dockerutil/dockerutil.go index 023c203dc..33c9e1094 100644 --- a/pkg/test/dockerutil/dockerutil.go +++ b/pkg/test/dockerutil/dockerutil.go @@ -131,7 +131,7 @@ func UsingSystemdCgroup() (bool, error) { return false, err } // Unmarshal the configuration. - c := make(map[string]interface{}) + c := make(map[string]any) if err := json.Unmarshal(configBytes, &c); err != nil { return false, err } @@ -141,7 +141,7 @@ func UsingSystemdCgroup() (bool, error) { // No exec-opts. Default is true on cgroupv2, false otherwise. return cgroup.IsOnlyV2(), nil } - eos, ok := e.([]interface{}) + eos, ok := e.([]any) if !ok { // The exec opts are not an array. return false, fmt.Errorf("unexpected format: %+v", eos) @@ -154,7 +154,7 @@ func UsingSystemdCgroup() (bool, error) { return false, nil } -func runtimeMap() (map[string]interface{}, error) { +func runtimeMap() (map[string]any, error) { // Read the configuration data; the file must exist. configBytes, err := ioutil.ReadFile(*config) if err != nil { @@ -162,7 +162,7 @@ func runtimeMap() (map[string]interface{}, error) { } // Unmarshal the configuration. - c := make(map[string]interface{}) + c := make(map[string]any) if err := json.Unmarshal(configBytes, &c); err != nil { return nil, err } @@ -172,7 +172,7 @@ func runtimeMap() (map[string]interface{}, error) { if !ok { return nil, fmt.Errorf("no runtimes declared: %v", c) } - rs, ok := r.(map[string]interface{}) + rs, ok := r.(map[string]any) if !ok { // The runtimes are not a map. return nil, fmt.Errorf("unexpected format: %v", rs) @@ -182,7 +182,7 @@ func runtimeMap() (map[string]interface{}, error) { // The expected runtime is not declared. return nil, fmt.Errorf("runtime %q not found: %v", *runtime, rs) } - rs, ok = r.(map[string]interface{}) + rs, ok = r.(map[string]any) if !ok { // The runtime is not a map. return nil, fmt.Errorf("unexpected format: %v", r) diff --git a/pkg/test/testutil/sh.go b/pkg/test/testutil/sh.go index cd5b0557a..46a3bef2b 100644 --- a/pkg/test/testutil/sh.go +++ b/pkg/test/testutil/sh.go @@ -140,7 +140,7 @@ func (s *Shell) logIO(prefix string, b []byte, err error) { } // logf logs something to both standard logging and the test log, if provided. -func (s *Shell) logf(prefix, format string, values ...interface{}) { +func (s *Shell) logf(prefix, format string, values ...any) { if s.logger != nil { s.logger.Logf("[%s] %s", prefix, fmt.Sprintf(format, values...)) } diff --git a/pkg/test/testutil/testutil.go b/pkg/test/testutil/testutil.go index 85e3b0f17..0236a6cff 100644 --- a/pkg/test/testutil/testutil.go +++ b/pkg/test/testutil/testutil.go @@ -159,7 +159,7 @@ func TmpDir() string { // This is designed to be implemented by *testing.T. type Logger interface { Name() string - Logf(fmt string, args ...interface{}) + Logf(fmt string, args ...any) } // DefaultLogger logs using the log package. @@ -171,7 +171,7 @@ func (d DefaultLogger) Name() string { } // Logf implements Logger.Logf. -func (d DefaultLogger) Logf(fmt string, args ...interface{}) { +func (d DefaultLogger) Logf(fmt string, args ...any) { log.Printf(fmt, args...) } @@ -188,7 +188,7 @@ func (m multiLogger) Name() string { } // Logf implements Logger.Logf. -func (m multiLogger) Logf(fmt string, args ...interface{}) { +func (m multiLogger) Logf(fmt string, args ...any) { for _, l := range m { l.Logf(fmt, args...) } diff --git a/pkg/trie/trie.go b/pkg/trie/trie.go index 4151d7c80..e432f7540 100644 --- a/pkg/trie/trie.go +++ b/pkg/trie/trie.go @@ -18,7 +18,7 @@ package trie // Visitor accepts a prefix string and an associated value, and returns true iff searching should // continue deeper into the Trie. It is used by FindMatching(). -type Visitor func(prefix string, value interface{}) bool +type Visitor func(prefix string, value any) bool // Trie stores data at given strings in tree structure, for linear-time retrieval. // Call New() to obtain a valid Trie. @@ -33,7 +33,7 @@ func New() *Trie { } type node struct { - value interface{} + value any children map[rune]*node } @@ -59,7 +59,7 @@ func (t *Trie) FindPrefixes(key string, f Visitor) { } } -func (t *Trie) updateNode(n *node, newValue interface{}) { +func (t *Trie) updateNode(n *node, newValue any) { if n.value != nil { t.size-- } @@ -70,7 +70,7 @@ func (t *Trie) updateNode(n *node, newValue interface{}) { } // SetValue associates the specified key with the given value, replacing any existing value. -func (t *Trie) SetValue(key string, value interface{}) { +func (t *Trie) SetValue(key string, value any) { cur := t.root for _, r := range key { next, ok := cur.children[r] diff --git a/pkg/trie/trie_test.go b/pkg/trie/trie_test.go index cadf1e53c..690e30cc5 100644 --- a/pkg/trie/trie_test.go +++ b/pkg/trie/trie_test.go @@ -28,7 +28,7 @@ type Entry struct { func collectPrefixes(tr *Trie, key string) []Entry { arr := make([]Entry, 0) - tr.FindPrefixes(key, func(p string, v interface{}) bool { + tr.FindPrefixes(key, func(p string, v any) bool { arr = append(arr, Entry{Key: p, Value: v.(string)}) return true }) @@ -37,7 +37,7 @@ func collectPrefixes(tr *Trie, key string) []Entry { func collectSuffixes(tr *Trie, key string) []Entry { arr := make([]Entry, 0) - tr.FindSuffixes(key, func(p string, v interface{}) bool { + tr.FindSuffixes(key, func(p string, v any) bool { arr = append(arr, Entry{Key: p, Value: v.(string)}) return true }) diff --git a/pkg/urpc/urpc.go b/pkg/urpc/urpc.go index ec63d1aec..2f6a6e0e2 100644 --- a/pkg/urpc/urpc.go +++ b/pkg/urpc/urpc.go @@ -107,8 +107,8 @@ type filePayloader interface { // clientCall is the client=>server method call on the client side. type clientCall struct { - Method string `json:"method"` - Arg interface{} `json:"arg"` + Method string `json:"method"` + Arg any `json:"arg"` } // serverCall is the client=>server method call on the server side. @@ -119,9 +119,9 @@ type serverCall struct { // callResult is the server=>client method call result. type callResult struct { - Success bool `json:"success"` - Err string `json:"err"` - Result interface{} `json:"result"` + Success bool `json:"success"` + Err string `json:"err"` + Result any `json:"result"` } // registeredMethod is method registered with the server. @@ -211,7 +211,7 @@ type Stopper interface { // tolerate any object with non-conforming methods. Any non-confirming methods // will lead to an immediate panic, instead of being skipped or an error. // Panics will also be generated by anonymous objects and duplicate entries. -func (s *Server) Register(obj interface{}) { +func (s *Server) Register(obj any) { s.mu.Lock() defer s.mu.Unlock() @@ -522,7 +522,7 @@ func NewClient(socket *unet.Socket) *Client { } // marshal sends the given FD and json struct. -func marshal(s *unet.Socket, v interface{}, fs []*os.File) error { +func marshal(s *unet.Socket, v any, fs []*os.File) error { // Marshal to a buffer. data, err := json.Marshal(v) if err != nil { @@ -570,7 +570,7 @@ func marshal(s *unet.Socket, v interface{}, fs []*os.File) error { } // unmarhsal receives an FD (optional) and unmarshals the given struct. -func unmarshal(s *unet.Socket, v interface{}) ([]*os.File, error) { +func unmarshal(s *unet.Socket, v any) ([]*os.File, error) { // Receive a single byte. r := s.Reader(true) r.EnableFDs(maxFiles) @@ -592,7 +592,7 @@ func unmarshal(s *unet.Socket, v interface{}) ([]*os.File, error) { // Read the rest. d := json.NewDecoder(io.MultiReader(bytes.NewBuffer(firstByte), s)) - // urpc internally decodes / re-encodes the data with interface{} as the + // urpc internally decodes / re-encodes the data with any as the // intermediate type. We have to unmarshal integers to json.Number type // instead of the default float type for those intermediate values, such // that when they get re-encoded, their values are not printed out in @@ -613,7 +613,7 @@ func unmarshal(s *unet.Socket, v interface{}) ([]*os.File, error) { } // Call calls a function. -func (c *Client) Call(method string, arg interface{}, result interface{}) error { +func (c *Client) Call(method string, arg any, result any) error { c.mu.Lock() defer c.mu.Unlock() diff --git a/runsc/boot/vfs.go b/runsc/boot/vfs.go index 4da525e83..4528ea33d 100644 --- a/runsc/boot/vfs.go +++ b/runsc/boot/vfs.go @@ -681,7 +681,7 @@ func (c *containerMounter) getMountNameAndOptions(conf *config.Config, m *mountA useOverlay := false var ( data []string - internalData interface{} + internalData any ) // Find filesystem name and FS specific data field. diff --git a/runsc/cgroup/cgroup.go b/runsc/cgroup/cgroup.go index 45b2c5b53..f9bea2f86 100644 --- a/runsc/cgroup/cgroup.go +++ b/runsc/cgroup/cgroup.go @@ -429,7 +429,7 @@ type cgroupJSONSystemd struct { } type cgroupJSONUnknown struct { - Cgroup interface{} `json:"cgroupunknown"` + Cgroup any `json:"cgroupunknown"` } // UnmarshalJSON implements json.Unmarshaler.UnmarshalJSON diff --git a/runsc/cgroup/systemd.go b/runsc/cgroup/systemd.go index 525b54bf0..f2eecd6d7 100644 --- a/runsc/cgroup/systemd.go +++ b/runsc/cgroup/systemd.go @@ -292,14 +292,14 @@ func addIOProps(props []systemdDbus.Property, name string, devs []specs.LinuxThr return props } -func (c *cgroupSystemd) addProp(name string, value interface{}) { +func (c *cgroupSystemd) addProp(name string, value any) { if value == nil { return } c.properties = append(c.properties, newProp(name, value)) } -func newProp(name string, units interface{}) systemdDbus.Property { +func newProp(name string, units any) systemdDbus.Property { return systemdDbus.Property{ Name: name, Value: dbus.MakeVariant(units), diff --git a/runsc/cgroup/systemd_test.go b/runsc/cgroup/systemd_test.go index 0b88903c4..308d61435 100644 --- a/runsc/cgroup/systemd_test.go +++ b/runsc/cgroup/systemd_test.go @@ -237,7 +237,7 @@ func filterProperties(got []systemdDbus.Property, want []systemdDbus.Property) [ if want == nil { return nil } - filterMap := map[string]interface{}{} + filterMap := map[string]any{} for _, prop := range want { filterMap[prop.Name] = nil } diff --git a/runsc/cmd/boot.go b/runsc/cmd/boot.go index b1615c79f..e47d48352 100644 --- a/runsc/cmd/boot.go +++ b/runsc/cmd/boot.go @@ -147,7 +147,7 @@ func (b *Boot) SetFlags(f *flag.FlagSet) { // Execute implements subcommands.Command.Execute. It starts a sandbox in a // waiting state. -func (b *Boot) Execute(_ context.Context, f *flag.FlagSet, args ...interface{}) subcommands.ExitStatus { +func (b *Boot) Execute(_ context.Context, f *flag.FlagSet, args ...any) subcommands.ExitStatus { if b.specFD == -1 || b.controllerFD == -1 || b.startSyncFD == -1 || f.NArg() != 1 { f.Usage() return subcommands.ExitUsageError diff --git a/runsc/cmd/checkpoint.go b/runsc/cmd/checkpoint.go index 4d73ebd11..cdc345638 100644 --- a/runsc/cmd/checkpoint.go +++ b/runsc/cmd/checkpoint.go @@ -65,7 +65,7 @@ func (c *Checkpoint) SetFlags(f *flag.FlagSet) { } // Execute implements subcommands.Command.Execute. -func (c *Checkpoint) Execute(_ context.Context, f *flag.FlagSet, args ...interface{}) subcommands.ExitStatus { +func (c *Checkpoint) Execute(_ context.Context, f *flag.FlagSet, args ...any) subcommands.ExitStatus { if f.NArg() != 1 { f.Usage() diff --git a/runsc/cmd/cmd.go b/runsc/cmd/cmd.go index 4bef9cfec..3c726bd24 100644 --- a/runsc/cmd/cmd.go +++ b/runsc/cmd/cmd.go @@ -35,7 +35,7 @@ func (i *intFlags) String() string { } // Get implements flag.Value. -func (i *intFlags) Get() interface{} { +func (i *intFlags) Get() any { return i } diff --git a/runsc/cmd/create.go b/runsc/cmd/create.go index 9c4a5663b..3c8541b12 100644 --- a/runsc/cmd/create.go +++ b/runsc/cmd/create.go @@ -75,7 +75,7 @@ func (c *Create) SetFlags(f *flag.FlagSet) { } // Execute implements subcommands.Command.Execute. -func (c *Create) Execute(_ context.Context, f *flag.FlagSet, args ...interface{}) subcommands.ExitStatus { +func (c *Create) Execute(_ context.Context, f *flag.FlagSet, args ...any) subcommands.ExitStatus { if f.NArg() != 1 { f.Usage() return subcommands.ExitUsageError diff --git a/runsc/cmd/debug.go b/runsc/cmd/debug.go index 983a56810..6d83c6460 100644 --- a/runsc/cmd/debug.go +++ b/runsc/cmd/debug.go @@ -85,7 +85,7 @@ func (d *Debug) SetFlags(f *flag.FlagSet) { } // Execute implements subcommands.Command.Execute. -func (d *Debug) Execute(_ context.Context, f *flag.FlagSet, args ...interface{}) subcommands.ExitStatus { +func (d *Debug) Execute(_ context.Context, f *flag.FlagSet, args ...any) subcommands.ExitStatus { var c *container.Container conf := args[0].(*config.Config) diff --git a/runsc/cmd/delete.go b/runsc/cmd/delete.go index 39bd0aaee..42ee3d1a6 100644 --- a/runsc/cmd/delete.go +++ b/runsc/cmd/delete.go @@ -54,7 +54,7 @@ func (d *Delete) SetFlags(f *flag.FlagSet) { } // Execute implements subcommands.Command.Execute. -func (d *Delete) Execute(_ context.Context, f *flag.FlagSet, args ...interface{}) subcommands.ExitStatus { +func (d *Delete) Execute(_ context.Context, f *flag.FlagSet, args ...any) subcommands.ExitStatus { if f.NArg() == 0 { f.Usage() return subcommands.ExitUsageError diff --git a/runsc/cmd/do.go b/runsc/cmd/do.go index 773070db2..b8e28dae0 100644 --- a/runsc/cmd/do.go +++ b/runsc/cmd/do.go @@ -82,7 +82,7 @@ func (is *idMapSlice) String() string { } // Get implements flag.Value.Get. -func (is *idMapSlice) Get() interface{} { +func (is *idMapSlice) Get() any { return is } @@ -124,7 +124,7 @@ func (c *Do) SetFlags(f *flag.FlagSet) { } // Execute implements subcommands.Command.Execute. -func (c *Do) Execute(_ context.Context, f *flag.FlagSet, args ...interface{}) subcommands.ExitStatus { +func (c *Do) Execute(_ context.Context, f *flag.FlagSet, args ...any) subcommands.ExitStatus { if len(f.Args()) == 0 { f.Usage() return subcommands.ExitUsageError @@ -211,7 +211,7 @@ func addNamespace(spec *specs.Spec, ns specs.LinuxNamespace) { spec.Linux.Namespaces = append(spec.Linux.Namespaces, ns) } -func (c *Do) notifyUser(format string, v ...interface{}) { +func (c *Do) notifyUser(format string, v ...any) { if !c.quiet { fmt.Printf(format+"\n", v...) } diff --git a/runsc/cmd/events.go b/runsc/cmd/events.go index 652167595..0b5d937c1 100644 --- a/runsc/cmd/events.go +++ b/runsc/cmd/events.go @@ -66,7 +66,7 @@ func (evs *Events) SetFlags(f *flag.FlagSet) { } // Execute implements subcommands.Command.Execute. -func (evs *Events) Execute(_ context.Context, f *flag.FlagSet, args ...interface{}) subcommands.ExitStatus { +func (evs *Events) Execute(_ context.Context, f *flag.FlagSet, args ...any) subcommands.ExitStatus { if f.NArg() != 1 { f.Usage() return subcommands.ExitUsageError diff --git a/runsc/cmd/exec.go b/runsc/cmd/exec.go index b39bc4f02..f995ce467 100644 --- a/runsc/cmd/exec.go +++ b/runsc/cmd/exec.go @@ -105,7 +105,7 @@ func (ex *Exec) SetFlags(f *flag.FlagSet) { // Execute implements subcommands.Command.Execute. It starts a process in an // already created container. -func (ex *Exec) Execute(_ context.Context, f *flag.FlagSet, args ...interface{}) subcommands.ExitStatus { +func (ex *Exec) Execute(_ context.Context, f *flag.FlagSet, args ...any) subcommands.ExitStatus { conf := args[0].(*config.Config) e, id, err := ex.parseArgs(f, conf.EnableRaw) if err != nil { @@ -414,7 +414,7 @@ func (ss *stringSlice) String() string { } // Get implements flag.Value.Get. -func (ss *stringSlice) Get() interface{} { +func (ss *stringSlice) Get() any { return ss } @@ -435,7 +435,7 @@ func (u *user) String() string { return fmt.Sprintf("%+v", *u) } -func (u *user) Get() interface{} { +func (u *user) Get() any { return u } diff --git a/runsc/cmd/gofer.go b/runsc/cmd/gofer.go index f3509c392..82af6a3c7 100644 --- a/runsc/cmd/gofer.go +++ b/runsc/cmd/gofer.go @@ -106,7 +106,7 @@ func (g *Gofer) SetFlags(f *flag.FlagSet) { } // Execute implements subcommands.Command. -func (g *Gofer) Execute(_ context.Context, f *flag.FlagSet, args ...interface{}) subcommands.ExitStatus { +func (g *Gofer) Execute(_ context.Context, f *flag.FlagSet, args ...any) subcommands.ExitStatus { if g.bundleDir == "" || len(g.ioFDs) < 1 || g.specFD < 0 { f.Usage() return subcommands.ExitUsageError diff --git a/runsc/cmd/help.go b/runsc/cmd/help.go index 35545e938..847f571a5 100644 --- a/runsc/cmd/help.go +++ b/runsc/cmd/help.go @@ -61,7 +61,7 @@ func (*Help) Usage() string { func (h *Help) SetFlags(*flag.FlagSet) {} // Execute implements subcommands.Command.Execute. -func (h *Help) Execute(ctx context.Context, f *flag.FlagSet, args ...interface{}) subcommands.ExitStatus { +func (h *Help) Execute(ctx context.Context, f *flag.FlagSet, args ...any) subcommands.ExitStatus { switch f.NArg() { case 0: fmt.Fprintf(h.cdr.Output, "Usage: %s \n\n", h.cdr.Name()) diff --git a/runsc/cmd/install.go b/runsc/cmd/install.go index 0856776a8..caaedf3dc 100644 --- a/runsc/cmd/install.go +++ b/runsc/cmd/install.go @@ -67,7 +67,7 @@ func (i *Install) SetFlags(fs *flag.FlagSet) { } // Execute implements subcommands.Command.Execute. -func (i *Install) Execute(_ context.Context, f *flag.FlagSet, _ ...interface{}) subcommands.ExitStatus { +func (i *Install) Execute(_ context.Context, f *flag.FlagSet, _ ...any) subcommands.ExitStatus { // Grab the name and arguments. i.runtimeArgs = f.Args() testFlags := flag.NewFlagSet("test", flag.ContinueOnError) @@ -120,7 +120,7 @@ func doInstallConfig(i *Install, rw configReaderWriter) error { return fmt.Errorf("error reading config file %q: %v", i.ConfigFile, err) } // Unmarshal the configuration. - c := make(map[string]interface{}) + c := make(map[string]any) if len(configBytes) > 0 { if err := json.Unmarshal(configBytes, &c); err != nil { return err @@ -128,11 +128,11 @@ func doInstallConfig(i *Install, rw configReaderWriter) error { } // Add the given runtime. - var rts map[string]interface{} + var rts map[string]any if i, ok := c["runtimes"]; ok { - rts = i.(map[string]interface{}) + rts = i.(map[string]any) } else { - rts = make(map[string]interface{}) + rts = make(map[string]any) c["runtimes"] = rts } updateRuntime := func() { @@ -168,8 +168,8 @@ func doInstallConfig(i *Install, rw configReaderWriter) error { if !ok { c["exec-opts"] = []string{fmt.Sprintf("native.cgroupdriver=%s", i.CgroupDriver)} } else { - opts := v.([]interface{}) - newOpts := []interface{}{} + opts := v.([]any) + newOpts := []any{} for _, opt := range opts { if !i.Clobber { newOpts = opts @@ -224,7 +224,7 @@ func (u *Uninstall) SetFlags(fs *flag.FlagSet) { } // Execute implements subcommands.Command.Execute. -func (u *Uninstall) Execute(context.Context, *flag.FlagSet, ...interface{}) subcommands.ExitStatus { +func (u *Uninstall) Execute(context.Context, *flag.FlagSet, ...any) subcommands.ExitStatus { log.Printf("Removing runtime %q from %q.", u.Runtime, u.ConfigFile) if err := doUninstallConfig(u, configReaderWriter{ read: defaultReadConfig, @@ -242,16 +242,16 @@ func doUninstallConfig(u *Uninstall, rw configReaderWriter) error { } // Unmarshal the configuration. - c := make(map[string]interface{}) + c := make(map[string]any) if len(configBytes) > 0 { if err := json.Unmarshal(configBytes, &c); err != nil { return err } } - var rts map[string]interface{} + var rts map[string]any if i, ok := c["runtimes"]; ok { - rts = i.(map[string]interface{}) + rts = i.(map[string]any) } else { return fmt.Errorf("runtime %q not found", u.Runtime) } @@ -268,7 +268,7 @@ func doUninstallConfig(u *Uninstall, rw configReaderWriter) error { type configReaderWriter struct { read func(string) ([]byte, error) - write func(map[string]interface{}, string) error + write func(map[string]any, string) error } func defaultReadConfig(path string) ([]byte, error) { @@ -280,7 +280,7 @@ func defaultReadConfig(path string) ([]byte, error) { return configBytes, nil } -func defaultWriteConfig(c map[string]interface{}, filename string) error { +func defaultWriteConfig(c map[string]any, filename string) error { // Marshal the configuration. b, err := json.MarshalIndent(c, "", " ") if err != nil { diff --git a/runsc/cmd/install_test.go b/runsc/cmd/install_test.go index f50e2a5b6..a7067bf0e 100644 --- a/runsc/cmd/install_test.go +++ b/runsc/cmd/install_test.go @@ -37,7 +37,7 @@ func (r *runtimeDef) MarshalJSON() ([]byte, error) { } func (r *runtimeDef) UnmarshalJSON(data []byte) error { - var dat map[string]interface{} + var dat map[string]any if err := json.Unmarshal(data, &dat); err != nil { return err } @@ -50,7 +50,7 @@ func (r *runtimeDef) UnmarshalJSON(data []byte) error { return nil } -var defaultInput = map[string]interface{}{ +var defaultInput = map[string]any{ "runtimes": map[string]*runtimeDef{ "runtime1": &runtimeDef{ path: "runtime1_path", @@ -73,8 +73,8 @@ func TestInstall(t *testing.T) { for _, tc := range []struct { name string i *Install - input map[string]interface{} - output map[string]interface{} + input map[string]any + output map[string]any }{ { name: "clobber", @@ -87,7 +87,7 @@ func TestInstall(t *testing.T) { runtimeArgs: []string{"new", "cool", "args"}, }, input: defaultInput, - output: map[string]interface{}{ + output: map[string]any{ "runtimes": map[string]*runtimeDef{ "runtime1": &runtimeDef{ path: "runtime1_path", @@ -117,7 +117,7 @@ func TestInstall(t *testing.T) { runtimeArgs: []string{"new", "cool", "args"}, }, input: defaultInput, - output: map[string]interface{}{ + output: map[string]any{ "runtimes": map[string]*runtimeDef{ "runtime1": &runtimeDef{ path: "runtime1_path", @@ -145,7 +145,7 @@ func TestInstall(t *testing.T) { runtimeArgs: []string{"new", "cool", "args"}, }, input: defaultInput, - output: map[string]interface{}{ + output: map[string]any{ "runtimes": map[string]*runtimeDef{ "runtime1": &runtimeDef{ path: "runtime1_path", @@ -176,7 +176,7 @@ func TestInstall(t *testing.T) { } got := []byte{} - mockWrite := func(c map[string]interface{}, _ string) error { + mockWrite := func(c map[string]any, _ string) error { res, err := json.MarshalIndent(c, "", " ") if err != nil { return err @@ -210,8 +210,8 @@ func TestUninstall(t *testing.T) { for _, tc := range []struct { name string u *Uninstall - input map[string]interface{} - output map[string]interface{} + input map[string]any + output map[string]any wantErr bool }{ { @@ -220,7 +220,7 @@ func TestUninstall(t *testing.T) { Runtime: "other runtime", }, input: defaultInput, - output: map[string]interface{}{ + output: map[string]any{ "runtimes": map[string]*runtimeDef{ "runtime1": &runtimeDef{ path: "runtime1_path", @@ -249,7 +249,7 @@ func TestUninstall(t *testing.T) { } got := []byte{} - mockWrite := func(c map[string]interface{}, _ string) error { + mockWrite := func(c map[string]any, _ string) error { res, err := json.MarshalIndent(c, "", " ") if err != nil { return err diff --git a/runsc/cmd/kill.go b/runsc/cmd/kill.go index 5c0c3ef38..df28aab8a 100644 --- a/runsc/cmd/kill.go +++ b/runsc/cmd/kill.go @@ -56,7 +56,7 @@ func (k *Kill) SetFlags(f *flag.FlagSet) { } // Execute implements subcommands.Command.Execute. -func (k *Kill) Execute(_ context.Context, f *flag.FlagSet, args ...interface{}) subcommands.ExitStatus { +func (k *Kill) Execute(_ context.Context, f *flag.FlagSet, args ...any) subcommands.ExitStatus { if f.NArg() == 0 || f.NArg() > 2 { f.Usage() return subcommands.ExitUsageError diff --git a/runsc/cmd/list.go b/runsc/cmd/list.go index 38582755f..d54e10169 100644 --- a/runsc/cmd/list.go +++ b/runsc/cmd/list.go @@ -59,7 +59,7 @@ func (l *List) SetFlags(f *flag.FlagSet) { } // Execute implements subcommands.Command.Execute. -func (l *List) Execute(_ context.Context, f *flag.FlagSet, args ...interface{}) subcommands.ExitStatus { +func (l *List) Execute(_ context.Context, f *flag.FlagSet, args ...any) subcommands.ExitStatus { if f.NArg() != 0 { f.Usage() return subcommands.ExitUsageError diff --git a/runsc/cmd/mitigate.go b/runsc/cmd/mitigate.go index 188abc4e0..2a0fa2be2 100644 --- a/runsc/cmd/mitigate.go +++ b/runsc/cmd/mitigate.go @@ -74,7 +74,7 @@ func (m *Mitigate) SetFlags(f *flag.FlagSet) { } // Execute implements subcommands.Command.Execute. -func (m *Mitigate) Execute(_ context.Context, f *flag.FlagSet, args ...interface{}) subcommands.ExitStatus { +func (m *Mitigate) Execute(_ context.Context, f *flag.FlagSet, args ...any) subcommands.ExitStatus { if runtime.GOARCH == "arm64" || runtime.GOARCH == "arm" { log.Warningf("As ARM is not affected by MDS, mitigate does not support ARM machines.") // Set reverse flag so that we still perform post mitigate operations. mitigate reverse is a noop in this case. diff --git a/runsc/cmd/pause.go b/runsc/cmd/pause.go index c37020a5c..37e214fba 100644 --- a/runsc/cmd/pause.go +++ b/runsc/cmd/pause.go @@ -47,7 +47,7 @@ func (*Pause) SetFlags(*flag.FlagSet) { } // Execute implements subcommands.Command.Execute. -func (*Pause) Execute(_ context.Context, f *flag.FlagSet, args ...interface{}) subcommands.ExitStatus { +func (*Pause) Execute(_ context.Context, f *flag.FlagSet, args ...any) subcommands.ExitStatus { if f.NArg() != 1 { f.Usage() return subcommands.ExitUsageError diff --git a/runsc/cmd/platforms.go b/runsc/cmd/platforms.go index e73729175..a68f12594 100644 --- a/runsc/cmd/platforms.go +++ b/runsc/cmd/platforms.go @@ -47,7 +47,7 @@ func (*Platforms) Usage() string { func (*Platforms) SetFlags(f *flag.FlagSet) {} // Execute implements subcommands.Command.Execute. -func (*Platforms) Execute(_ context.Context, f *flag.FlagSet, args ...interface{}) subcommands.ExitStatus { +func (*Platforms) Execute(_ context.Context, f *flag.FlagSet, args ...any) subcommands.ExitStatus { for _, p := range platform.List() { fmt.Fprintf(os.Stdout, "%s\n", p) } diff --git a/runsc/cmd/ps.go b/runsc/cmd/ps.go index 2900c570e..a0737bf7c 100644 --- a/runsc/cmd/ps.go +++ b/runsc/cmd/ps.go @@ -52,7 +52,7 @@ func (ps *PS) SetFlags(f *flag.FlagSet) { } // Execute implements subcommands.Command.Execute. -func (ps *PS) Execute(ctx context.Context, f *flag.FlagSet, args ...interface{}) subcommands.ExitStatus { +func (ps *PS) Execute(ctx context.Context, f *flag.FlagSet, args ...any) subcommands.ExitStatus { if f.NArg() != 1 { f.Usage() return subcommands.ExitUsageError diff --git a/runsc/cmd/read_control.go b/runsc/cmd/read_control.go index 61cbe7abe..c3a3bdeac 100644 --- a/runsc/cmd/read_control.go +++ b/runsc/cmd/read_control.go @@ -57,7 +57,7 @@ EXAMPLE: func (r *ReadControl) SetFlags(f *flag.FlagSet) {} // Execute implements subcommands.Command.Execute. -func (r *ReadControl) Execute(_ context.Context, f *flag.FlagSet, args ...interface{}) subcommands.ExitStatus { +func (r *ReadControl) Execute(_ context.Context, f *flag.FlagSet, args ...any) subcommands.ExitStatus { if f.NArg() < 4 { f.Usage() return subcommands.ExitUsageError diff --git a/runsc/cmd/restore.go b/runsc/cmd/restore.go index 2d46c0781..5bab839f5 100644 --- a/runsc/cmd/restore.go +++ b/runsc/cmd/restore.go @@ -71,7 +71,7 @@ func (r *Restore) SetFlags(f *flag.FlagSet) { } // Execute implements subcommands.Command.Execute. -func (r *Restore) Execute(_ context.Context, f *flag.FlagSet, args ...interface{}) subcommands.ExitStatus { +func (r *Restore) Execute(_ context.Context, f *flag.FlagSet, args ...any) subcommands.ExitStatus { if f.NArg() != 1 { f.Usage() return subcommands.ExitUsageError diff --git a/runsc/cmd/resume.go b/runsc/cmd/resume.go index c466f3776..c2c465d5b 100644 --- a/runsc/cmd/resume.go +++ b/runsc/cmd/resume.go @@ -48,7 +48,7 @@ func (r *Resume) SetFlags(*flag.FlagSet) { } // Execute implements subcommands.Command.Execute. -func (r *Resume) Execute(_ context.Context, f *flag.FlagSet, args ...interface{}) subcommands.ExitStatus { +func (r *Resume) Execute(_ context.Context, f *flag.FlagSet, args ...any) subcommands.ExitStatus { if f.NArg() != 1 { f.Usage() return subcommands.ExitUsageError diff --git a/runsc/cmd/run.go b/runsc/cmd/run.go index 6a361f20d..7f75c9b34 100644 --- a/runsc/cmd/run.go +++ b/runsc/cmd/run.go @@ -58,7 +58,7 @@ func (r *Run) SetFlags(f *flag.FlagSet) { } // Execute implements subcommands.Command.Execute. -func (r *Run) Execute(_ context.Context, f *flag.FlagSet, args ...interface{}) subcommands.ExitStatus { +func (r *Run) Execute(_ context.Context, f *flag.FlagSet, args ...any) subcommands.ExitStatus { if f.NArg() != 1 { f.Usage() return subcommands.ExitUsageError diff --git a/runsc/cmd/spec.go b/runsc/cmd/spec.go index 038353f4b..6bf789177 100644 --- a/runsc/cmd/spec.go +++ b/runsc/cmd/spec.go @@ -180,7 +180,7 @@ func (s *Spec) SetFlags(f *flag.FlagSet) { } // Execute implements subcommands.Command.Execute. -func (s *Spec) Execute(_ context.Context, f *flag.FlagSet, args ...interface{}) subcommands.ExitStatus { +func (s *Spec) Execute(_ context.Context, f *flag.FlagSet, args ...any) subcommands.ExitStatus { // Grab the arguments. containerArgs := f.Args() if len(containerArgs) == 0 { diff --git a/runsc/cmd/start.go b/runsc/cmd/start.go index 30dcaa0f0..d66d7f4f3 100644 --- a/runsc/cmd/start.go +++ b/runsc/cmd/start.go @@ -47,7 +47,7 @@ func (*Start) Usage() string { func (*Start) SetFlags(*flag.FlagSet) {} // Execute implements subcommands.Command.Execute. -func (*Start) Execute(_ context.Context, f *flag.FlagSet, args ...interface{}) subcommands.ExitStatus { +func (*Start) Execute(_ context.Context, f *flag.FlagSet, args ...any) subcommands.ExitStatus { if f.NArg() != 1 { f.Usage() return subcommands.ExitUsageError diff --git a/runsc/cmd/state.go b/runsc/cmd/state.go index 89a739838..606987d5a 100644 --- a/runsc/cmd/state.go +++ b/runsc/cmd/state.go @@ -49,7 +49,7 @@ func (*State) Usage() string { func (*State) SetFlags(*flag.FlagSet) {} // Execute implements subcommands.Command.Execute. -func (*State) Execute(_ context.Context, f *flag.FlagSet, args ...interface{}) subcommands.ExitStatus { +func (*State) Execute(_ context.Context, f *flag.FlagSet, args ...any) subcommands.ExitStatus { if f.NArg() != 1 { f.Usage() return subcommands.ExitUsageError diff --git a/runsc/cmd/statefile.go b/runsc/cmd/statefile.go index 91a04944c..180ecbd16 100644 --- a/runsc/cmd/statefile.go +++ b/runsc/cmd/statefile.go @@ -60,7 +60,7 @@ func (s *Statefile) SetFlags(f *flag.FlagSet) { } // Execute implements subcommands.Command.Execute. -func (s *Statefile) Execute(_ context.Context, f *flag.FlagSet, args ...interface{}) subcommands.ExitStatus { +func (s *Statefile) Execute(_ context.Context, f *flag.FlagSet, args ...any) subcommands.ExitStatus { // Check arguments. if s.list && s.get != "" { util.Fatalf("error: can't specify -list and -get simultaneously.") diff --git a/runsc/cmd/symbolize.go b/runsc/cmd/symbolize.go index 68c4c941f..934ade3ce 100644 --- a/runsc/cmd/symbolize.go +++ b/runsc/cmd/symbolize.go @@ -61,7 +61,7 @@ func (c *Symbolize) SetFlags(f *flag.FlagSet) { } // Execute implements subcommands.Command.Execute. -func (c *Symbolize) Execute(_ context.Context, f *flag.FlagSet, args ...interface{}) subcommands.ExitStatus { +func (c *Symbolize) Execute(_ context.Context, f *flag.FlagSet, args ...any) subcommands.ExitStatus { if f.NArg() != 0 { f.Usage() return subcommands.ExitUsageError diff --git a/runsc/cmd/syscalls.go b/runsc/cmd/syscalls.go index 9596fc561..06dec4ae1 100644 --- a/runsc/cmd/syscalls.go +++ b/runsc/cmd/syscalls.go @@ -104,7 +104,7 @@ func (s *Syscalls) SetFlags(f *flag.FlagSet) { } // Execute implements subcommands.Command.Execute. -func (s *Syscalls) Execute(context.Context, *flag.FlagSet, ...interface{}) subcommands.ExitStatus { +func (s *Syscalls) Execute(context.Context, *flag.FlagSet, ...any) subcommands.ExitStatus { out, ok := outputMap[s.format] if !ok { util.Fatalf("Unsupported output format %q", s.format) diff --git a/runsc/cmd/trace/create.go b/runsc/cmd/trace/create.go index 59b4ccb1d..b236588ac 100644 --- a/runsc/cmd/trace/create.go +++ b/runsc/cmd/trace/create.go @@ -59,7 +59,7 @@ func (l *create) SetFlags(f *flag.FlagSet) { } // Execute implements subcommands.Command. -func (l *create) Execute(_ context.Context, f *flag.FlagSet, args ...interface{}) subcommands.ExitStatus { +func (l *create) Execute(_ context.Context, f *flag.FlagSet, args ...any) subcommands.ExitStatus { if f.NArg() != 1 { f.Usage() return subcommands.ExitUsageError diff --git a/runsc/cmd/trace/create_test.go b/runsc/cmd/trace/create_test.go index 301ea9cf7..e7befb101 100644 --- a/runsc/cmd/trace/create_test.go +++ b/runsc/cmd/trace/create_test.go @@ -37,7 +37,7 @@ func TestConfigFile(t *testing.T) { for _, tc := range []struct { name string - json interface{} + json any want seccheck.SessionConfig err string }{ diff --git a/runsc/cmd/trace/delete.go b/runsc/cmd/trace/delete.go index 76ae0eb6a..f4197437d 100644 --- a/runsc/cmd/trace/delete.go +++ b/runsc/cmd/trace/delete.go @@ -52,7 +52,7 @@ func (l *delete) SetFlags(f *flag.FlagSet) { } // Execute implements subcommands.Command. -func (l *delete) Execute(_ context.Context, f *flag.FlagSet, args ...interface{}) subcommands.ExitStatus { +func (l *delete) Execute(_ context.Context, f *flag.FlagSet, args ...any) subcommands.ExitStatus { if f.NArg() != 1 { f.Usage() return subcommands.ExitUsageError diff --git a/runsc/cmd/trace/list.go b/runsc/cmd/trace/list.go index 37f16ec39..190d28dca 100644 --- a/runsc/cmd/trace/list.go +++ b/runsc/cmd/trace/list.go @@ -48,7 +48,7 @@ func (*list) Usage() string { func (*list) SetFlags(*flag.FlagSet) {} // Execute implements subcommands.Command. -func (l *list) Execute(_ context.Context, f *flag.FlagSet, args ...interface{}) subcommands.ExitStatus { +func (l *list) Execute(_ context.Context, f *flag.FlagSet, args ...any) subcommands.ExitStatus { if f.NArg() != 1 { f.Usage() return subcommands.ExitUsageError diff --git a/runsc/cmd/trace/metadata.go b/runsc/cmd/trace/metadata.go index 28b21fa1f..c3fe1d9ed 100644 --- a/runsc/cmd/trace/metadata.go +++ b/runsc/cmd/trace/metadata.go @@ -48,7 +48,7 @@ func (*metadata) Usage() string { func (*metadata) SetFlags(*flag.FlagSet) {} // Execute implements subcommands.Command. -func (l *metadata) Execute(context.Context, *flag.FlagSet, ...interface{}) subcommands.ExitStatus { +func (l *metadata) Execute(context.Context, *flag.FlagSet, ...any) subcommands.ExitStatus { // Sort to keep related points together. points := make([]seccheck.PointDesc, 0, len(seccheck.Points)) for _, pt := range seccheck.Points { diff --git a/runsc/cmd/trace/procfs.go b/runsc/cmd/trace/procfs.go index 11cb808b9..58a79b048 100644 --- a/runsc/cmd/trace/procfs.go +++ b/runsc/cmd/trace/procfs.go @@ -51,7 +51,7 @@ func (*procfs) Usage() string { func (*procfs) SetFlags(*flag.FlagSet) {} // Execute implements subcommands.Command. -func (*procfs) Execute(_ context.Context, f *flag.FlagSet, args ...interface{}) subcommands.ExitStatus { +func (*procfs) Execute(_ context.Context, f *flag.FlagSet, args ...any) subcommands.ExitStatus { if f.NArg() != 1 { f.Usage() return subcommands.ExitUsageError diff --git a/runsc/cmd/trace/trace.go b/runsc/cmd/trace/trace.go index d5a1d6450..842fc6325 100644 --- a/runsc/cmd/trace/trace.go +++ b/runsc/cmd/trace/trace.go @@ -53,7 +53,7 @@ func (*Trace) Usage() string { func (*Trace) SetFlags(f *flag.FlagSet) {} // Execute implements subcommands.Command. -func (*Trace) Execute(ctx context.Context, f *flag.FlagSet, args ...interface{}) subcommands.ExitStatus { +func (*Trace) Execute(ctx context.Context, f *flag.FlagSet, args ...any) subcommands.ExitStatus { return createCommander(f).Execute(ctx, args...) } diff --git a/runsc/cmd/usage.go b/runsc/cmd/usage.go index fed6b82cc..50c436ae8 100644 --- a/runsc/cmd/usage.go +++ b/runsc/cmd/usage.go @@ -53,7 +53,7 @@ func (u *Usage) SetFlags(f *flag.FlagSet) { } // Execute implements subcommands.Command.Execute. -func (u *Usage) Execute(_ context.Context, f *flag.FlagSet, args ...interface{}) subcommands.ExitStatus { +func (u *Usage) Execute(_ context.Context, f *flag.FlagSet, args ...any) subcommands.ExitStatus { if f.NArg() < 1 { f.Usage() return subcommands.ExitUsageError diff --git a/runsc/cmd/util/util.go b/runsc/cmd/util/util.go index c38d37e59..b5cc6ef2a 100644 --- a/runsc/cmd/util/util.go +++ b/runsc/cmd/util/util.go @@ -47,7 +47,7 @@ func (i *Writer) Write(data []byte) (n int, err error) { } // Infof writes message to log and stdout. -func Infof(format string, args ...interface{}) { +func Infof(format string, args ...any) { log.Infof(format, args) fmt.Printf(format+"\n", args) } @@ -57,7 +57,7 @@ func Infof(format string, args ...interface{}) { // methods: // // return Errorf("Danger! Danger!") -func Errorf(format string, args ...interface{}) subcommands.ExitStatus { +func Errorf(format string, args ...any) subcommands.ExitStatus { // If runsc is being invoked by docker or cri-o, then we might not have // access to stderr, so we log a serious-looking warning in addition to // writing to stderr. @@ -81,7 +81,7 @@ func Errorf(format string, args ...interface{}) subcommands.ExitStatus { } // Fatalf logs the same way as Errorf() does, plus *exits* the process. -func Fatalf(format string, args ...interface{}) { +func Fatalf(format string, args ...any) { Errorf(format, args...) // Return an error that is unlikely to be used by the application. os.Exit(128) diff --git a/runsc/cmd/wait.go b/runsc/cmd/wait.go index 23f7ae4af..279f28949 100644 --- a/runsc/cmd/wait.go +++ b/runsc/cmd/wait.go @@ -60,7 +60,7 @@ func (wt *Wait) SetFlags(f *flag.FlagSet) { // Execute implements subcommands.Command.Execute. It waits for a process in a // container to exit before returning. -func (wt *Wait) Execute(_ context.Context, f *flag.FlagSet, args ...interface{}) subcommands.ExitStatus { +func (wt *Wait) Execute(_ context.Context, f *flag.FlagSet, args ...any) subcommands.ExitStatus { if f.NArg() != 1 { f.Usage() return subcommands.ExitUsageError diff --git a/runsc/cmd/write_control.go b/runsc/cmd/write_control.go index 92ede65f0..73e6443ed 100644 --- a/runsc/cmd/write_control.go +++ b/runsc/cmd/write_control.go @@ -57,7 +57,7 @@ EXAMPLE: func (r *WriteControl) SetFlags(f *flag.FlagSet) {} // Execute implements subcommands.Command.Execute. -func (r *WriteControl) Execute(_ context.Context, f *flag.FlagSet, args ...interface{}) subcommands.ExitStatus { +func (r *WriteControl) Execute(_ context.Context, f *flag.FlagSet, args ...any) subcommands.ExitStatus { if f.NArg() < 5 { f.Usage() return subcommands.ExitUsageError diff --git a/runsc/config/config.go b/runsc/config/config.go index 245bdc16b..9b643b342 100644 --- a/runsc/config/config.go +++ b/runsc/config/config.go @@ -347,7 +347,7 @@ func (f *FileAccessType) Set(v string) error { } // Get implements flag.Value. -func (f *FileAccessType) Get() interface{} { +func (f *FileAccessType) Get() any { return *f } @@ -396,7 +396,7 @@ func (n *NetworkType) Set(v string) error { } // Get implements flag.Value. -func (n *NetworkType) Get() interface{} { +func (n *NetworkType) Get() any { return *n } @@ -443,7 +443,7 @@ func (q *QueueingDiscipline) Set(v string) error { } // Get implements flag.Value. -func (q *QueueingDiscipline) Get() interface{} { +func (q *QueueingDiscipline) Get() any { return *q } @@ -505,7 +505,7 @@ func (g *HostUDS) Set(v string) error { } // Get implements flag.Value. -func (g *HostUDS) Get() interface{} { +func (g *HostUDS) Get() any { return *g } @@ -567,7 +567,7 @@ func (g *HostFifo) Set(v string) error { } // Get implements flag.Value. -func (g *HostFifo) Get() interface{} { +func (g *HostFifo) Get() any { return *g } diff --git a/runsc/container/state_file.go b/runsc/container/state_file.go index 4888dd454..ab096f982 100644 --- a/runsc/container/state_file.go +++ b/runsc/container/state_file.go @@ -307,7 +307,7 @@ func (s *StateFile) unlockOrDie() { // saveLocked saves 'v' to the state file. // // Preconditions: lock() must been called before. -func (s *StateFile) saveLocked(v interface{}) error { +func (s *StateFile) saveLocked(v any) error { if !s.flock.Locked() { panic("saveLocked called without lock held") } @@ -322,7 +322,7 @@ func (s *StateFile) saveLocked(v interface{}) error { return nil } -func (s *StateFile) load(v interface{}) error { +func (s *StateFile) load(v any) error { if err := s.lock(); err != nil { return err } diff --git a/runsc/container/trace_test.go b/runsc/container/trace_test.go index 369df613d..2a84301ab 100644 --- a/runsc/container/trace_test.go +++ b/runsc/container/trace_test.go @@ -36,7 +36,7 @@ import ( func remoteSinkConfig(endpoint string) seccheck.SinkConfig { return seccheck.SinkConfig{ Name: "remote", - Config: map[string]interface{}{ + Config: map[string]any{ "endpoint": endpoint, }, } diff --git a/runsc/flag/flag.go b/runsc/flag/flag.go index 20d1984d1..37c638c1d 100644 --- a/runsc/flag/flag.go +++ b/runsc/flag/flag.go @@ -46,6 +46,6 @@ var ( const ContinueOnError = flag.ContinueOnError // Get returns the flag's underlying object. -func Get(v flag.Value) interface{} { +func Get(v flag.Value) any { return v.(flag.Getter).Get() } diff --git a/runsc/specutils/namespace.go b/runsc/specutils/namespace.go index cdf108b4b..4ae39da1c 100644 --- a/runsc/specutils/namespace.go +++ b/runsc/specutils/namespace.go @@ -170,7 +170,7 @@ func StartInNS(cmd *exec.Cmd, nss []specs.LinuxNamespace) error { // we can't destroy the current system thread, because // a child process is execited with Pdeathsig. log.Debugf("Block the current system thread due to: %s", err) - c := make(chan interface{}) + c := make(chan any) <-c } }() diff --git a/test/benchmarks/harness/util.go b/test/benchmarks/harness/util.go index 528a3a01d..ae1712170 100644 --- a/test/benchmarks/harness/util.go +++ b/test/benchmarks/harness/util.go @@ -52,7 +52,7 @@ func DropCaches(machine Machine) error { } // DebugLog prints debug messages if the debug flag is set. -func DebugLog(b *testing.B, msg string, args ...interface{}) { +func DebugLog(b *testing.B, msg string, args ...any) { b.Helper() if *debug { b.Logf(msg, args...) diff --git a/test/cmd/test_app/fds.go b/test/cmd/test_app/fds.go index 9b5f7231a..89e49c33b 100644 --- a/test/cmd/test_app/fds.go +++ b/test/cmd/test_app/fds.go @@ -56,7 +56,7 @@ func (fds *fdSender) SetFlags(f *flag.FlagSet) { } // Execute implements subcommands.Command.Execute. -func (fds *fdSender) Execute(ctx context.Context, f *flag.FlagSet, args ...interface{}) subcommands.ExitStatus { +func (fds *fdSender) Execute(ctx context.Context, f *flag.FlagSet, args ...any) subcommands.ExitStatus { if fds.socketPath == "" { log.Fatalf("socket flag must be set") } @@ -123,7 +123,7 @@ func (fdr *fdReceiver) SetFlags(f *flag.FlagSet) { } // Execute implements subcommands.Command.Execute. -func (fdr *fdReceiver) Execute(ctx context.Context, f *flag.FlagSet, args ...interface{}) subcommands.ExitStatus { +func (fdr *fdReceiver) Execute(ctx context.Context, f *flag.FlagSet, args ...any) subcommands.ExitStatus { if fdr.socketPath == "" { log.Fatalf("Flags cannot be empty, given: socket: %q", fdr.socketPath) } diff --git a/test/cmd/test_app/main.go b/test/cmd/test_app/main.go index 2d08ce2db..9fe792cf2 100644 --- a/test/cmd/test_app/main.go +++ b/test/cmd/test_app/main.go @@ -82,7 +82,7 @@ func (c *uds) SetFlags(f *flag.FlagSet) { } // Execute implements subcommands.Command.Execute. -func (c *uds) Execute(ctx context.Context, f *flag.FlagSet, args ...interface{}) subcommands.ExitStatus { +func (c *uds) Execute(ctx context.Context, f *flag.FlagSet, args ...any) subcommands.ExitStatus { if c.fileName == "" || c.socketPath == "" { log.Fatalf("Flags cannot be empty, given: fileName: %q, socketPath: %q", c.fileName, c.socketPath) return subcommands.ExitFailure @@ -159,7 +159,7 @@ func (c *taskTree) SetFlags(f *flag.FlagSet) { } // Execute implements subcommands.Command. -func (c *taskTree) Execute(ctx context.Context, f *flag.FlagSet, args ...interface{}) subcommands.ExitStatus { +func (c *taskTree) Execute(ctx context.Context, f *flag.FlagSet, args ...any) subcommands.ExitStatus { if c.depth == 0 { log.Printf("Child sleeping, PID: %d\n", os.Getpid()) for { @@ -227,7 +227,7 @@ func (c *forkBomb) SetFlags(f *flag.FlagSet) { } // Execute implements subcommands.Command. -func (c *forkBomb) Execute(ctx context.Context, f *flag.FlagSet, args ...interface{}) subcommands.ExitStatus { +func (c *forkBomb) Execute(ctx context.Context, f *flag.FlagSet, args ...any) subcommands.ExitStatus { time.Sleep(c.delay) cmd := exec.Command("/proc/self/exe", c.Name()) @@ -260,7 +260,7 @@ func (*reaper) Usage() string { func (*reaper) SetFlags(*flag.FlagSet) {} // Execute implements subcommands.Command. -func (c *reaper) Execute(ctx context.Context, f *flag.FlagSet, args ...interface{}) subcommands.ExitStatus { +func (c *reaper) Execute(ctx context.Context, f *flag.FlagSet, args ...any) subcommands.ExitStatus { stop := testutil.StartReaper() defer stop() select {} @@ -291,7 +291,7 @@ func (s *syscall) SetFlags(f *flag.FlagSet) { } // Execute implements subcommands.Command. -func (s *syscall) Execute(ctx context.Context, f *flag.FlagSet, args ...interface{}) subcommands.ExitStatus { +func (s *syscall) Execute(ctx context.Context, f *flag.FlagSet, args ...any) subcommands.ExitStatus { if _, _, errno := sys.Syscall(uintptr(s.sysno), 0, 0, 0); errno != 0 { fmt.Printf("syscall(%d, 0, 0...) failed: %v\n", s.sysno, errno) } else { @@ -327,7 +327,7 @@ func (c *capability) SetFlags(f *flag.FlagSet) { } // Execute implements subcommands.Command. -func (c *capability) Execute(ctx context.Context, f *flag.FlagSet, args ...interface{}) subcommands.ExitStatus { +func (c *capability) Execute(ctx context.Context, f *flag.FlagSet, args ...any) subcommands.ExitStatus { if c.enabled == 0 && c.disabled == 0 { fmt.Println("One of the flags must be set") return subcommands.ExitUsageError @@ -383,7 +383,7 @@ func (*ptyRunner) Usage() string { func (*ptyRunner) SetFlags(f *flag.FlagSet) {} // Execute implements subcommands.Command. -func (*ptyRunner) Execute(_ context.Context, fs *flag.FlagSet, _ ...interface{}) subcommands.ExitStatus { +func (*ptyRunner) Execute(_ context.Context, fs *flag.FlagSet, _ ...any) subcommands.ExitStatus { c := exec.Command(fs.Args()[0], fs.Args()[1:]...) f, err := pty.Start(c) if err != nil { diff --git a/test/iptables/nat.go b/test/iptables/nat.go index 0f25b6a18..9a50b8995 100644 --- a/test/iptables/nat.go +++ b/test/iptables/nat.go @@ -804,10 +804,10 @@ func recvWithRECVORIGDSTADDR(ctx context.Context, ipv6 bool, expectedDst *net.IP return fmt.Errorf("failed SetsockoptByte(%d, %d, %d, 1): %v", sockfd, level, option, err) } - addrCh := make(chan interface{}) + addrCh := make(chan any) errCh := make(chan error) go func() { - var addr interface{} + var addr any var err error if ipv6 { addr, err = recvOrigDstAddr6(sockfd) @@ -822,7 +822,7 @@ func recvWithRECVORIGDSTADDR(ctx context.Context, ipv6 bool, expectedDst *net.IP }() // Wait to receive a packet. - var addr interface{} + var addr any select { case <-ctx.Done(): return ctx.Err() diff --git a/test/packetimpact/testbench/layers.go b/test/packetimpact/testbench/layers.go index a3c897399..01474662b 100644 --- a/test/packetimpact/testbench/layers.go +++ b/test/packetimpact/testbench/layers.go @@ -102,8 +102,8 @@ func equalLayer(x, y Layer) bool { return true } // opt ignores comparison pairs where either of the inputs is a nil. - opt := cmp.FilterValues(func(x, y interface{}) bool { - for _, l := range []interface{}{x, y} { + opt := cmp.FilterValues(func(x, y any) bool { + for _, l := range []any{x, y} { v := reflect.ValueOf(l) if (v.Kind() == reflect.Ptr || v.Kind() == reflect.Slice) && v.IsNil() { return true diff --git a/test/root/crictl_test.go b/test/root/crictl_test.go index 958da3eb7..122a737e3 100644 --- a/test/root/crictl_test.go +++ b/test/root/crictl_test.go @@ -45,7 +45,7 @@ import ( // containerd instance. func Sandbox(name string) string { // Sandbox is a default JSON config for a sandbox. - s := map[string]interface{}{ + s := map[string]any{ "metadata": map[string]string{ "name": name, "namespace": "default", @@ -65,8 +65,8 @@ func Sandbox(name string) string { // SimpleSpec returns a JSON config for a simple container that runs the // specified command in the specified image. -func SimpleSpec(name, image string, cmd []string, extra map[string]interface{}) string { - s := map[string]interface{}{ +func SimpleSpec(name, image string, cmd []string, extra map[string]any) string { + s := map[string]any{ "metadata": map[string]string{ "name": name, }, @@ -122,8 +122,8 @@ func TestCrictlSanity(t *testing.T) { // HttpdMountPaths is a JSON config for an httpd container with additional // mounts. -var HttpdMountPaths = SimpleSpec("httpd", "basic/httpd", nil, map[string]interface{}{ - "mounts": []map[string]interface{}{ +var HttpdMountPaths = SimpleSpec("httpd", "basic/httpd", nil, map[string]any{ + "mounts": []map[string]any{ { "container_path": "/var/run/secrets/kubernetes.io/serviceaccount", "host_path": "/var/lib/kubelet/pods/82bae206-cdf5-11e8-b245-8cdcd43ac064/volumes/kubernetes.io~secret/default-token-2rpfx", @@ -145,7 +145,7 @@ var HttpdMountPaths = SimpleSpec("httpd", "basic/httpd", nil, map[string]interfa "readonly": true, }, }, - "linux": map[string]interface{}{}, + "linux": map[string]any{}, }) // TestMountPaths refers to b/117635704. diff --git a/test/runner/main.go b/test/runner/main.go index 7c15c2f94..5e917461e 100644 --- a/test/runner/main.go +++ b/test/runner/main.go @@ -508,7 +508,7 @@ func filterEnv(env, exclude []string) []string { return out } -func fatalf(s string, args ...interface{}) { +func fatalf(s string, args ...any) { fmt.Fprintf(os.Stderr, s+"\n", args...) os.Exit(1) } diff --git a/test/runtimes/runner/lib/lib.go b/test/runtimes/runner/lib/lib.go index a25fc1dc6..f6f8e851d 100644 --- a/test/runtimes/runner/lib/lib.go +++ b/test/runtimes/runner/lib/lib.go @@ -266,7 +266,7 @@ func (f testDeps) CoordinateFuzzing(time.Duration, int64, time.Duration, int64, } func (f testDeps) RunFuzzWorker(func(corpusEntry) error) error { return nil } func (f testDeps) ReadCorpus(string, []reflect.Type) ([]corpusEntry, error) { return nil, nil } -func (f testDeps) CheckCorpus([]interface{}, []reflect.Type) error { return nil } +func (f testDeps) CheckCorpus([]any, []reflect.Type) error { return nil } func (f testDeps) ResetCoverage() {} func (f testDeps) SnapshotCoverage() {} @@ -275,7 +275,7 @@ type corpusEntry = struct { Parent string Path string Data []byte - Values []interface{} + Values []any Generation int IsSeed bool } diff --git a/test/trace/trace_test.go b/test/trace/trace_test.go index c7bca782c..e3cc3e1e3 100644 --- a/test/trace/trace_test.go +++ b/test/trace/trace_test.go @@ -53,7 +53,7 @@ func TestAll(t *testing.T) { } builder.AddSink(seccheck.SinkConfig{ Name: "remote", - Config: map[string]interface{}{ + Config: map[string]any{ "endpoint": server.Endpoint, }, }) diff --git a/tools/bigquery/bigquery.go b/tools/bigquery/bigquery.go index 43f072ab5..7e6c42b7e 100644 --- a/tools/bigquery/bigquery.go +++ b/tools/bigquery/bigquery.go @@ -48,7 +48,7 @@ func (s *Suite) String() string { } // writeLine writes a line of text to the given string builder with a prefix. -func writeLine(sb *strings.Builder, prefix string, format string, values ...interface{}) { +func writeLine(sb *strings.Builder, prefix string, format string, values ...any) { if prefix != "" { sb.WriteString(prefix) } diff --git a/tools/checkaligned/checkaligned.go b/tools/checkaligned/checkaligned.go index a0fa23b7c..b71ea8059 100644 --- a/tools/checkaligned/checkaligned.go +++ b/tools/checkaligned/checkaligned.go @@ -59,7 +59,7 @@ var blocklist = []string{ "SwapUint32", } -func run(pass *analysis.Pass) (interface{}, error) { +func run(pass *analysis.Pass) (any, error) { // Check for the "// +checkalignedignore" escape hatch. for _, file := range pass.Files { if file.Doc == nil { diff --git a/tools/checkescape/checkescape.go b/tools/checkescape/checkescape.go index 61426f32b..2ceee2d8d 100644 --- a/tools/checkescape/checkescape.go +++ b/tools/checkescape/checkescape.go @@ -176,7 +176,7 @@ type objdumpAnalyzer struct { } // Run implements nogo.binaryAnalyzer.Run. -func (ob *objdumpAnalyzer) Run(pass *analysis.Pass, binary io.Reader) (interface{}, error) { +func (ob *objdumpAnalyzer) Run(pass *analysis.Pass, binary io.Reader) (any, error) { return run(pass, binary) } @@ -652,7 +652,7 @@ func findReasons(pass *analysis.Pass, fdecl *ast.FuncDecl) ([]EscapeReason, bool } // run performs the analysis. -func run(pass *analysis.Pass, binary io.Reader) (interface{}, error) { +func run(pass *analysis.Pass, binary io.Reader) (any, error) { calls, callsErr := loadObjdump(binary) if callsErr != nil { // Note that if this analysis fails, then we don't actually diff --git a/tools/checkinfo/checkinfo.go b/tools/checkinfo/checkinfo.go index cc7ea7d0f..702847099 100644 --- a/tools/checkinfo/checkinfo.go +++ b/tools/checkinfo/checkinfo.go @@ -129,7 +129,7 @@ func walkScope(pass *analysis.Pass, scope *types.Scope) { } } -func run(pass *analysis.Pass) (interface{}, error) { +func run(pass *analysis.Pass) (any, error) { // Export all facts. walkScope(pass, pass.Pkg.Scope()) return nil, nil diff --git a/tools/checklinkname/check_linkname.go b/tools/checklinkname/check_linkname.go index 5373dd762..f342ce87e 100644 --- a/tools/checklinkname/check_linkname.go +++ b/tools/checklinkname/check_linkname.go @@ -208,7 +208,7 @@ func checkOneRemote(pass *analysis.Pass, sym, wantSig string) { } } -func run(pass *analysis.Pass) (interface{}, error) { +func run(pass *analysis.Pass) (any, error) { // First, check if any remote symbols are in this package. p, ok := knownLinknames[pass.Pkg.Path()] if ok { diff --git a/tools/checklocks/annotations.go b/tools/checklocks/annotations.go index 9e328edbb..62a4f2e3b 100644 --- a/tools/checklocks/annotations.go +++ b/tools/checklocks/annotations.go @@ -83,7 +83,7 @@ func (pc *passContext) addForce(pos token.Pos) { } // maybeFail checks a potential failure against a specific failure map. -func (pc *passContext) maybeFail(pos token.Pos, fmtStr string, args ...interface{}) { +func (pc *passContext) maybeFail(pos token.Pos, fmtStr string, args ...any) { if fd, ok := pc.failures[pc.positionKey(pos)]; ok { fd.seen++ return diff --git a/tools/checklocks/checklocks.go b/tools/checklocks/checklocks.go index 70921a15c..9474863c1 100644 --- a/tools/checklocks/checklocks.go +++ b/tools/checklocks/checklocks.go @@ -128,7 +128,7 @@ func (pc *passContext) forAllFunctions(fn func(fn *ast.FuncDecl)) { } // run is the main entrypoint. -func run(pass *analysis.Pass) (interface{}, error) { +func run(pass *analysis.Pass) (any, error) { pc := &passContext{ pass: pass, failures: make(map[positionKey]*failData), diff --git a/tools/checklocks/facts.go b/tools/checklocks/facts.go index 2d9d6380a..d978a2bee 100644 --- a/tools/checklocks/facts.go +++ b/tools/checklocks/facts.go @@ -138,7 +138,7 @@ type functionGuardResolver interface { // resolveStatic is used to resolve a guard during static analysis, // e.g. based on static annotations applied to a method. The function's // ssa object is available, as well as the return value. - resolveStatic(pc *passContext, ls *lockState, fn *ssa.Function, rv interface{}) resolvedValue + resolveStatic(pc *passContext, ls *lockState, fn *ssa.Function, rv any) resolvedValue // resolveCall is used to resolve a guard during a call. The ssa // return value is available from the instruction context where the @@ -191,7 +191,7 @@ func (g *globalGuard) resolveCommon(pc *passContext, ls *lockState) resolvedValu } // resolveStatic implements functionGuardResolver.resolveStatic. -func (g *globalGuard) resolveStatic(pc *passContext, ls *lockState, _ *ssa.Function, v interface{}) resolvedValue { +func (g *globalGuard) resolveStatic(pc *passContext, ls *lockState, _ *ssa.Function, v any) resolvedValue { return g.resolveCommon(pc, ls) } @@ -227,7 +227,7 @@ type parameterGuard struct { } // resolveStatic implements functionGuardResolver.resolveStatic. -func (p *parameterGuard) resolveStatic(_ *passContext, _ *lockState, fn *ssa.Function, _ interface{}) resolvedValue { +func (p *parameterGuard) resolveStatic(_ *passContext, _ *lockState, fn *ssa.Function, _ any) resolvedValue { return makeResolvedValue(fn.Params[p.Index], p.FieldList) } @@ -250,7 +250,7 @@ type returnGuard struct { } // resolveCommon implements resolution for both cases. -func (r *returnGuard) resolveCommon(rv interface{}) resolvedValue { +func (r *returnGuard) resolveCommon(rv any) resolvedValue { if rv == nil { // For defers and other objects, this may be nil. This is // handled in state.go in the actual lock checking logic. This @@ -286,7 +286,7 @@ func (r *returnGuard) resolveCommon(rv interface{}) resolvedValue { } // resolveStatic implements functionGuardResolver.resolveStatic. -func (r *returnGuard) resolveStatic(_ *passContext, _ *lockState, _ *ssa.Function, rv interface{}) resolvedValue { +func (r *returnGuard) resolveStatic(_ *passContext, _ *lockState, _ *ssa.Function, rv any) resolvedValue { return r.resolveCommon(rv) } diff --git a/tools/checkunsafe/check_unsafe.go b/tools/checkunsafe/check_unsafe.go index 4ccd7cc5a..0e99af065 100644 --- a/tools/checkunsafe/check_unsafe.go +++ b/tools/checkunsafe/check_unsafe.go @@ -31,7 +31,7 @@ var Analyzer = &analysis.Analyzer{ Run: run, } -func run(pass *analysis.Pass) (interface{}, error) { +func run(pass *analysis.Pass) (any, error) { for _, f := range pass.Files { for _, imp := range f.Imports { // Is this an unsafe import? diff --git a/tools/go_generics/go_merge/main.go b/tools/go_generics/go_merge/main.go index 81394ddce..2e46a3d3b 100644 --- a/tools/go_generics/go_merge/main.go +++ b/tools/go_generics/go_merge/main.go @@ -33,7 +33,7 @@ var ( output = flag.String("o", "", "output `file`") ) -func fatalf(s string, args ...interface{}) { +func fatalf(s string, args ...any) { fmt.Fprintf(os.Stderr, s, args...) os.Exit(1) } diff --git a/tools/go_generics/tests/all_stmts/input.go b/tools/go_generics/tests/all_stmts/input.go index 7ebe7c40e..1f24699bf 100644 --- a/tools/go_generics/tests/all_stmts/input.go +++ b/tools/go_generics/tests/all_stmts/input.go @@ -237,7 +237,7 @@ R: // Type switch statements. { - var interfaceFunc func(T) interface{} + var interfaceFunc func(T) any switch interfaceFunc(T(0)).(type) { case *T, T, int: diff --git a/tools/go_generics/tests/all_stmts/output.go b/tools/go_generics/tests/all_stmts/output.go index a33944d85..5cc92eb19 100644 --- a/tools/go_generics/tests/all_stmts/output.go +++ b/tools/go_generics/tests/all_stmts/output.go @@ -235,7 +235,7 @@ R: // Type switch statements. { - var interfaceFunc func(Q) interface{} + var interfaceFunc func(Q) any switch interfaceFunc(Q(0)).(type) { case *Q, Q, int: diff --git a/tools/go_marshal/analysis/analysis_unsafe.go b/tools/go_marshal/analysis/analysis_unsafe.go index 7a3d6bbea..a43159475 100644 --- a/tools/go_marshal/analysis/analysis_unsafe.go +++ b/tools/go_marshal/analysis/analysis_unsafe.go @@ -47,7 +47,7 @@ import ( // pointers to active go objects (pointer fields aren't allowed in ABI // structs anyways), or we'd be violating the go runtime contract and // the GC may malfunction. -func RandomizeValue(x interface{}) { +func RandomizeValue(x any) { v := reflect.Indirect(reflect.ValueOf(x)) if !v.CanSet() { panic("RandomizeType() called with an unaddressable value. You probably need to pass a pointer to the argument") diff --git a/tools/go_marshal/gomarshal/util.go b/tools/go_marshal/gomarshal/util.go index 69dbae320..fb33be404 100644 --- a/tools/go_marshal/gomarshal/util.go +++ b/tools/go_marshal/gomarshal/util.go @@ -147,7 +147,7 @@ func abortAt(p token.Position, msg string) { } // debugf conditionally prints a debug message. -func debugf(f string, a ...interface{}) { +func debugf(f string, a ...any) { if debugEnabled() { fmt.Printf(f, a...) } @@ -155,7 +155,7 @@ func debugf(f string, a ...interface{}) { // debugfAt conditionally prints a debug message with a reference to a position // in the input source. -func debugfAt(p token.Position, f string, a ...interface{}) { +func debugfAt(p token.Position, f string, a ...any) { if debugEnabled() { fmt.Printf("%s:\n %s", p, fmt.Sprintf(f, a...)) } @@ -178,7 +178,7 @@ func debugfAt(p token.Position, f string, a ...interface{}) { // // Calling emit with a single argument that is not a string will result in a // panic, as the caller's intent is ambiguous. -func emit(out io.Writer, indent int, a ...interface{}) { +func emit(out io.Writer, indent int, a ...any) { const spacesPerIndentLevel = 4 if len(a) < 1 { @@ -245,11 +245,11 @@ func (b *sourceBuffer) decIndent() { b.indent-- } -func (b *sourceBuffer) emit(a ...interface{}) { +func (b *sourceBuffer) emit(a ...any) { emit(&b.b, b.indent, a...) } -func (b *sourceBuffer) emitNoIndent(a ...interface{}) { +func (b *sourceBuffer) emitNoIndent(a ...any) { emit(&b.b, 0 /*indent*/, a...) } diff --git a/tools/go_marshal/test/marshal_test.go b/tools/go_marshal/test/marshal_test.go index dec3e84fd..cb2aa16d1 100644 --- a/tools/go_marshal/test/marshal_test.go +++ b/tools/go_marshal/test/marshal_test.go @@ -44,7 +44,7 @@ type mockCopyContext struct { } // populate fills the task memory with the contents of val. -func (t *mockCopyContext) populate(val interface{}) { +func (t *mockCopyContext) populate(val any) { var buf bytes.Buffer // Use binary.Write so we aren't testing go-marshal against its own // potentially buggy implementation. @@ -120,7 +120,7 @@ func unsafeMemory(m marshal.Marshallable) []byte { // returned slice is related to m, the caller must ensure m lives long enough. // // Precondition: m must be a slice. -func unsafeMemorySlice(m interface{}, elt marshal.Marshallable) []byte { +func unsafeMemorySlice(m any, elt marshal.Marshallable) []byte { kind := reflect.TypeOf(m).Kind() if kind != reflect.Slice { panic("unsafeMemorySlice called on non-slice") @@ -305,52 +305,52 @@ func TestLimitedMarshalling(t *testing.T) { func TestLimitedSliceMarshalling(t *testing.T) { types := []struct { arrayPtrType reflect.Type - copySliceIn func(cc marshal.CopyContext, addr hostarch.Addr, dstSlice interface{}) (int, error) - copySliceOut func(cc marshal.CopyContext, addr hostarch.Addr, srcSlice interface{}) (int, error) - unsafeMemory func(arrPtr interface{}) []byte + copySliceIn func(cc marshal.CopyContext, addr hostarch.Addr, dstSlice any) (int, error) + copySliceOut func(cc marshal.CopyContext, addr hostarch.Addr, srcSlice any) (int, error) + unsafeMemory func(arrPtr any) []byte }{ // Packed types. { reflect.TypeOf((*[20]test.Stat)(nil)), - func(cc marshal.CopyContext, addr hostarch.Addr, dst interface{}) (int, error) { + func(cc marshal.CopyContext, addr hostarch.Addr, dst any) (int, error) { slice := dst.(*[20]test.Stat)[:] return test.CopyStatSliceIn(cc, addr, slice) }, - func(cc marshal.CopyContext, addr hostarch.Addr, src interface{}) (int, error) { + func(cc marshal.CopyContext, addr hostarch.Addr, src any) (int, error) { slice := src.(*[20]test.Stat)[:] return test.CopyStatSliceOut(cc, addr, slice) }, - func(a interface{}) []byte { + func(a any) []byte { slice := a.(*[20]test.Stat)[:] return unsafeMemorySlice(slice, &slice[0]) }, }, { reflect.TypeOf((*[1]test.Stat)(nil)), - func(cc marshal.CopyContext, addr hostarch.Addr, dst interface{}) (int, error) { + func(cc marshal.CopyContext, addr hostarch.Addr, dst any) (int, error) { slice := dst.(*[1]test.Stat)[:] return test.CopyStatSliceIn(cc, addr, slice) }, - func(cc marshal.CopyContext, addr hostarch.Addr, src interface{}) (int, error) { + func(cc marshal.CopyContext, addr hostarch.Addr, src any) (int, error) { slice := src.(*[1]test.Stat)[:] return test.CopyStatSliceOut(cc, addr, slice) }, - func(a interface{}) []byte { + func(a any) []byte { slice := a.(*[1]test.Stat)[:] return unsafeMemorySlice(slice, &slice[0]) }, }, { reflect.TypeOf((*[5]test.SignalSetAlias)(nil)), - func(cc marshal.CopyContext, addr hostarch.Addr, dst interface{}) (int, error) { + func(cc marshal.CopyContext, addr hostarch.Addr, dst any) (int, error) { slice := dst.(*[5]test.SignalSetAlias)[:] return test.CopySignalSetAliasSliceIn(cc, addr, slice) }, - func(cc marshal.CopyContext, addr hostarch.Addr, src interface{}) (int, error) { + func(cc marshal.CopyContext, addr hostarch.Addr, src any) (int, error) { slice := src.(*[5]test.SignalSetAlias)[:] return test.CopySignalSetAliasSliceOut(cc, addr, slice) }, - func(a interface{}) []byte { + func(a any) []byte { slice := a.(*[5]test.SignalSetAlias)[:] return unsafeMemorySlice(slice, &slice[0]) }, @@ -358,45 +358,45 @@ func TestLimitedSliceMarshalling(t *testing.T) { // Non-packed types. { reflect.TypeOf((*[20]test.Type1)(nil)), - func(cc marshal.CopyContext, addr hostarch.Addr, dst interface{}) (int, error) { + func(cc marshal.CopyContext, addr hostarch.Addr, dst any) (int, error) { slice := dst.(*[20]test.Type1)[:] return test.CopyType1SliceIn(cc, addr, slice) }, - func(cc marshal.CopyContext, addr hostarch.Addr, src interface{}) (int, error) { + func(cc marshal.CopyContext, addr hostarch.Addr, src any) (int, error) { slice := src.(*[20]test.Type1)[:] return test.CopyType1SliceOut(cc, addr, slice) }, - func(a interface{}) []byte { + func(a any) []byte { slice := a.(*[20]test.Type1)[:] return unsafeMemorySlice(slice, &slice[0]) }, }, { reflect.TypeOf((*[1]test.Type1)(nil)), - func(cc marshal.CopyContext, addr hostarch.Addr, dst interface{}) (int, error) { + func(cc marshal.CopyContext, addr hostarch.Addr, dst any) (int, error) { slice := dst.(*[1]test.Type1)[:] return test.CopyType1SliceIn(cc, addr, slice) }, - func(cc marshal.CopyContext, addr hostarch.Addr, src interface{}) (int, error) { + func(cc marshal.CopyContext, addr hostarch.Addr, src any) (int, error) { slice := src.(*[1]test.Type1)[:] return test.CopyType1SliceOut(cc, addr, slice) }, - func(a interface{}) []byte { + func(a any) []byte { slice := a.(*[1]test.Type1)[:] return unsafeMemorySlice(slice, &slice[0]) }, }, { reflect.TypeOf((*[7]test.Type8)(nil)), - func(cc marshal.CopyContext, addr hostarch.Addr, dst interface{}) (int, error) { + func(cc marshal.CopyContext, addr hostarch.Addr, dst any) (int, error) { slice := dst.(*[7]test.Type8)[:] return test.CopyType8SliceIn(cc, addr, slice) }, - func(cc marshal.CopyContext, addr hostarch.Addr, src interface{}) (int, error) { + func(cc marshal.CopyContext, addr hostarch.Addr, src any) (int, error) { slice := src.(*[7]test.Type8)[:] return test.CopyType8SliceOut(cc, addr, slice) }, - func(a interface{}) []byte { + func(a any) []byte { slice := a.(*[7]test.Type8)[:] return unsafeMemorySlice(slice, &slice[0]) }, @@ -428,7 +428,7 @@ func TestLimitedSliceMarshalling(t *testing.T) { elem := reflect.New(arrayTy.Elem()).Interface().(marshal.Marshallable) // Equivalent: - // var expected, actual interface{} + // var expected, actual any // expected = new([20]test.Stat) // actual = new([20]test.Stat) expected := reflect.New(arrayTy).Interface() @@ -483,7 +483,7 @@ func TestLimitedSliceMarshalling(t *testing.T) { elem := reflect.New(arrayTy.Elem()).Interface().(marshal.Marshallable) // Equivalent: - // var expected, actual interface{} + // var expected, actual any // expected = new([20]test.Stat) // actual = new([20]test.Stat) expected := reflect.New(arrayTy).Interface() diff --git a/tools/go_stateify/main.go b/tools/go_stateify/main.go index 3cf00b5dd..c63febd59 100644 --- a/tools/go_stateify/main.go +++ b/tools/go_stateify/main.go @@ -353,7 +353,7 @@ func main() { emitField(name) } emitLoadValue := func(name, typName string) { - fmt.Fprintf(outputFile, " stateSourceObject.LoadValue(%d, new(%s), func(y interface{}) { %s.load%s(y.(%s)) })\n", fields[name], typName, recv, camelCased(name), typName) + fmt.Fprintf(outputFile, " stateSourceObject.LoadValue(%d, new(%s), func(y any) { %s.load%s(y.(%s)) })\n", fields[name], typName, recv, camelCased(name), typName) } emitLoad := func(name string) { fmt.Fprintf(outputFile, " stateSourceObject.Load(%d, &%s.%s)\n", fields[name], recv, name) diff --git a/tools/nogo/check/analyzers.go b/tools/nogo/check/analyzers.go index 1108ca840..5be48f448 100644 --- a/tools/nogo/check/analyzers.go +++ b/tools/nogo/check/analyzers.go @@ -61,7 +61,7 @@ import ( // operation to run an analyzer with the object binary data. type binaryAnalyzer interface { // Run runs the analyzer with the given binary data. - Run(*analysis.Pass, io.Reader) (interface{}, error) + Run(*analysis.Pass, io.Reader) (any, error) } // analyzer is a simple analysis.Analyzer interface. diff --git a/tools/nogo/check/check.go b/tools/nogo/check/check.go index 25231d3b4..96f2d4fa4 100644 --- a/tools/nogo/check/check.go +++ b/tools/nogo/check/check.go @@ -388,7 +388,7 @@ func (i *importer) checkPackage(path string, srcs []string) (*types.Package, Fin resultsMu sync.RWMutex // protects results & errs, findings. factsMu sync.RWMutex // protects facts. ready = make(map[*analysis.Analyzer]*sync.WaitGroup) - results = make(map[*analysis.Analyzer]interface{}) + results = make(map[*analysis.Analyzer]any) errs = make(map[*analysis.Analyzer]error) findings = make(FindingSet, 0) ) @@ -541,7 +541,7 @@ func (i *importer) checkPackage(path string, srcs []string) (*types.Package, Fin // specific analyzers. The only panic that can happen // is while resultsMu is held as a read-only lock. var ( - result interface{} + result any err error ) defer func() { diff --git a/tools/nogo/cli/cli.go b/tools/nogo/cli/cli.go index 04969e526..23295754f 100644 --- a/tools/nogo/cli/cli.go +++ b/tools/nogo/cli/cli.go @@ -62,7 +62,7 @@ func closeOutput(w io.Writer) { } // failure exits with the given failure message. -func failure(fmtStr string, v ...interface{}) subcommands.ExitStatus { +func failure(fmtStr string, v ...any) subcommands.ExitStatus { fmt.Fprintf(os.Stderr, fmtStr+"\n", v...) return subcommands.ExitFailure } @@ -179,7 +179,7 @@ func (c *Check) SetFlags(fs *flag.FlagSet) { } // Execute implements subcommands.Command.Execute. -func (c *Check) Execute(ctx context.Context, fs *flag.FlagSet, args ...interface{}) subcommands.ExitStatus { +func (c *Check) Execute(ctx context.Context, fs *flag.FlagSet, args ...any) subcommands.ExitStatus { if c.Package == "" { c.Package = "main" // Default, no imports. } @@ -230,7 +230,7 @@ func (b *Bundle) SetFlags(fs *flag.FlagSet) { } // Execute implements subcommands.Command.Execute. -func (b *Bundle) Execute(ctx context.Context, fs *flag.FlagSet, args ...interface{}) subcommands.ExitStatus { +func (b *Bundle) Execute(ctx context.Context, fs *flag.FlagSet, args ...any) subcommands.ExitStatus { // Perform the analysis. if err := b.execute(func() (check.FindingSet, facts.Serializer, error) { // Discover the correct common root. @@ -286,7 +286,7 @@ func (s *Stdlib) SetFlags(fs *flag.FlagSet) { } // Execute implements subcommands.Command.Execute. -func (s *Stdlib) Execute(ctx context.Context, fs *flag.FlagSet, args ...interface{}) subcommands.ExitStatus { +func (s *Stdlib) Execute(ctx context.Context, fs *flag.FlagSet, args ...any) subcommands.ExitStatus { if fs.NArg() != 0 { return subcommands.ExitUsageError // Need no arguments. } @@ -398,7 +398,7 @@ func loadConfigs(filenames []string) (*config.Config, error) { } // Execute implements subcommands.Command.Execute. -func (f *Filter) Execute(ctx context.Context, fs *flag.FlagSet, args ...interface{}) subcommands.ExitStatus { +func (f *Filter) Execute(ctx context.Context, fs *flag.FlagSet, args ...any) subcommands.ExitStatus { // Open and merge all configuations. config, err := loadConfigs(f.Configs) if err != nil { @@ -492,7 +492,7 @@ func (r *Render) SetFlags(fs *flag.FlagSet) { } // Execute implements subcommands.Command.Execute. -func (r *Render) Execute(ctx context.Context, fs *flag.FlagSet, args ...interface{}) subcommands.ExitStatus { +func (r *Render) Execute(ctx context.Context, fs *flag.FlagSet, args ...any) subcommands.ExitStatus { // Open the output file. output, err := openOutput(r.Output, os.Stdout) if err != nil { diff --git a/tools/nogo/facts/facts.go b/tools/nogo/facts/facts.go index 1a76afbed..7de3a1edc 100644 --- a/tools/nogo/facts/facts.go +++ b/tools/nogo/facts/facts.go @@ -38,7 +38,7 @@ type Serializer interface { // item is used for serialiation. type item struct { Key string - Value interface{} + Value any } // writeItems is an implementation of Serialize. @@ -257,12 +257,12 @@ func (b *Bundle) Package(pkg *types.Package) (*Package, error) { } // Resolved is a human-readable fact format. -type Resolved map[string]interface{} +type Resolved map[string]any // addRecursively adds a entry to a map recursively. // // Precondition: len(names) > 0. -func (r Resolved) addRecursively(names []string, value interface{}) { +func (r Resolved) addRecursively(names []string, value any) { start := r for i := 0; i < len(names)-1; i++ { m, ok := start[names[i]] diff --git a/tools/nogo/flags/flags.go b/tools/nogo/flags/flags.go index 44f9dae9f..45e604f9d 100644 --- a/tools/nogo/flags/flags.go +++ b/tools/nogo/flags/flags.go @@ -83,7 +83,7 @@ func (s *StringList) Set(value string) error { } // Get implements flag.Value.Get. -func (s *StringList) Get() interface{} { +func (s *StringList) Get() any { return *s } @@ -100,7 +100,7 @@ func (s *StringMap) String() string { } // Get implements flag.Value.Get. -func (s *StringMap) Get() interface{} { +func (s *StringMap) Get() any { return *s } diff --git a/tools/parsers/parser_main.go b/tools/parsers/parser_main.go index 01396494a..65ec00dcb 100644 --- a/tools/parsers/parser_main.go +++ b/tools/parsers/parser_main.go @@ -140,7 +140,7 @@ Available commands: log.Printf(usage, initCmd.Name(), initDescription, parseCmd.Name(), parseDescription) } -func debugLog(msg string, args ...interface{}) { +func debugLog(msg string, args ...any) { if *debug { log.Printf(msg, args...) } diff --git a/tools/tracereplay/main/main.go b/tools/tracereplay/main/main.go index 9ce18a2b6..0c963acf1 100644 --- a/tools/tracereplay/main/main.go +++ b/tools/tracereplay/main/main.go @@ -67,7 +67,7 @@ func (c *saveCmd) SetFlags(f *flag.FlagSet) { } // Execute implements subcommands.Command. -func (c *saveCmd) Execute(_ context.Context, f *flag.FlagSet, args ...interface{}) subcommands.ExitStatus { +func (c *saveCmd) Execute(_ context.Context, f *flag.FlagSet, args ...any) subcommands.ExitStatus { if f.NArg() > 0 { fmt.Fprintf(os.Stderr, "unexpected argument: %s\n", f.Args()) return subcommands.ExitUsageError @@ -130,7 +130,7 @@ func (c *replayCmd) SetFlags(f *flag.FlagSet) { } // Execute implements subcommands.Command. -func (c *replayCmd) Execute(_ context.Context, f *flag.FlagSet, _ ...interface{}) subcommands.ExitStatus { +func (c *replayCmd) Execute(_ context.Context, f *flag.FlagSet, _ ...any) subcommands.ExitStatus { if f.NArg() > 0 { fmt.Fprintf(os.Stderr, "unexpected argument: %s\n", f.Args()) return subcommands.ExitUsageError diff --git a/tools/xdp/drop.go b/tools/xdp/drop.go index a069d7c95..2d7c29f42 100644 --- a/tools/xdp/drop.go +++ b/tools/xdp/drop.go @@ -54,7 +54,7 @@ func (pc *DropCommand) SetFlags(fs *flag.FlagSet) { } // Execute implements subcommands.Command.Execute. -func (pc *DropCommand) Execute(context.Context, *flag.FlagSet, ...interface{}) subcommands.ExitStatus { +func (pc *DropCommand) Execute(context.Context, *flag.FlagSet, ...any) subcommands.ExitStatus { if err := runBasicProgram(dropProgram, pc.device, pc.deviceIndex); err != nil { log.Printf("%v", err) return subcommands.ExitFailure diff --git a/tools/xdp/pass.go b/tools/xdp/pass.go index 2bc99e44c..a47eedeb9 100644 --- a/tools/xdp/pass.go +++ b/tools/xdp/pass.go @@ -54,7 +54,7 @@ func (pc *PassCommand) SetFlags(fs *flag.FlagSet) { } // Execute implements subcommands.Command.Execute. -func (pc *PassCommand) Execute(context.Context, *flag.FlagSet, ...interface{}) subcommands.ExitStatus { +func (pc *PassCommand) Execute(context.Context, *flag.FlagSet, ...any) subcommands.ExitStatus { if err := runBasicProgram(passProgram, pc.device, pc.deviceIndex); err != nil { log.Printf("%v", err) return subcommands.ExitFailure diff --git a/tools/xdp/tcpdump.go b/tools/xdp/tcpdump.go index ac651755c..4a5e1624b 100644 --- a/tools/xdp/tcpdump.go +++ b/tools/xdp/tcpdump.go @@ -64,7 +64,7 @@ func (pc *TcpdumpCommand) SetFlags(fs *flag.FlagSet) { } // Execute implements subcommands.Command.Execute. -func (pc *TcpdumpCommand) Execute(context.Context, *flag.FlagSet, ...interface{}) subcommands.ExitStatus { +func (pc *TcpdumpCommand) Execute(context.Context, *flag.FlagSet, ...any) subcommands.ExitStatus { if err := pc.execute(); err != nil { fmt.Printf("%v", err) return subcommands.ExitFailure diff --git a/tools/yamltest/main.go b/tools/yamltest/main.go index b9d8cc3db..b7485bb22 100644 --- a/tools/yamltest/main.go +++ b/tools/yamltest/main.go @@ -31,11 +31,11 @@ var ( strict = flag.Bool("strict", true, "Whether to enable strict mode for YAML decoding") ) -func fixup(v interface{}) (interface{}, error) { +func fixup(v any) (any, error) { switch x := v.(type) { - case map[interface{}]interface{}: + case map[any]any: // Coerse into a string-based map, required for yaml. - strMap := make(map[string]interface{}) + strMap := make(map[string]any) for k, v := range x { strK, ok := k.(string) if !ok { @@ -49,7 +49,7 @@ func fixup(v interface{}) (interface{}, error) { strMap[strK] = fv } return strMap, nil - case []interface{}: + case []any: for i := range x { fv, err := fixup(x[i]) if err != nil { @@ -71,7 +71,7 @@ func loadFile(filename string) (gojsonschema.JSONLoader, error) { defer f.Close() dec := yaml.NewDecoder(f) dec.SetStrict(*strict) - var object interface{} + var object any if err := dec.Decode(&object); err != nil { return nil, err } diff --git a/webhook/pkg/injector/webhook.go b/webhook/pkg/injector/webhook.go index b4725eaef..cf2cc136a 100644 --- a/webhook/pkg/injector/webhook.go +++ b/webhook/pkg/injector/webhook.go @@ -132,7 +132,7 @@ func Admit(writer http.ResponseWriter, req *http.Request) { sendResponse(writer, review) } -func sendResponse(writer http.ResponseWriter, response interface{}) { +func sendResponse(writer http.ResponseWriter, response any) { b, err := json.Marshal(response) if err != nil { log.Warningf("Failed with error (%v) to marshal response: %+v", err, response) @@ -198,7 +198,7 @@ func updatePod(pod *v1.Pod) { } } -func createPatch(old []byte, newObj interface{}) ([]byte, error) { +func createPatch(old []byte, newObj any) ([]byte, error) { new, err := json.Marshal(newObj) if err != nil { return nil, err diff --git a/website/cmd/syscalldocs/main.go b/website/cmd/syscalldocs/main.go index 830d2bac7..ffd7be91a 100644 --- a/website/cmd/syscalldocs/main.go +++ b/website/cmd/syscalldocs/main.go @@ -88,7 +88,7 @@ syscalls. {{if .Undocumented}}{{.Undocumented}} syscalls are not yet documented. `)) // Fatalf writes a message to stderr and exits with error code 1 -func Fatalf(format string, a ...interface{}) { +func Fatalf(format string, a ...any) { fmt.Fprintf(os.Stderr, format, a...) os.Exit(1) }