Skip to content

Commit

Permalink
chore: replace interface{} with any
Browse files Browse the repository at this point in the history
  • Loading branch information
romshark committed Jan 24, 2025
1 parent 6e7f052 commit c78197f
Show file tree
Hide file tree
Showing 73 changed files with 179 additions and 179 deletions.
6 changes: 3 additions & 3 deletions control/beaconing/propagator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func TestPropagatorRunNonCore(t *testing.T) {
}
g := graph.NewDefaultGraph(mctrl)
provider.EXPECT().BeaconsToPropagate(gomock.Any()).Times(1).DoAndReturn(
func(_ interface{}) ([]beacon.Beacon, error) {
func(_ any) ([]beacon.Beacon, error) {
res := make([]beacon.Beacon, 0, len(beacons))
for _, desc := range beacons {
res = append(res, testBeacon(g, desc))
Expand Down Expand Up @@ -157,7 +157,7 @@ func TestPropagatorRunCore(t *testing.T) {
}
g := graph.NewDefaultGraph(mctrl)
provider.EXPECT().BeaconsToPropagate(gomock.Any()).Times(2).DoAndReturn(
func(_ interface{}) ([]beacon.Beacon, error) {
func(_ any) ([]beacon.Beacon, error) {
res := make([]beacon.Beacon, 0, len(beacons))
for _, desc := range beacons {
res = append(res, testBeacon(g, desc))
Expand Down Expand Up @@ -248,7 +248,7 @@ func TestPropagatorFastRecovery(t *testing.T) {
// We call run 4 times in this test, since the interface to 1-ff00:0:120
// will never be beaconed on, because the beacons are filtered for loops.
provider.EXPECT().BeaconsToPropagate(gomock.Any()).Times(4).DoAndReturn(
func(_ interface{}) ([]beacon.Beacon, error) {
func(_ any) ([]beacon.Beacon, error) {
return []beacon.Beacon{testBeacon(g, beacons[0])}, nil
},
)
Expand Down
4 changes: 2 additions & 2 deletions control/beaconing/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,9 @@ type silentLogger struct {
log.Logger
}

func (s silentLogger) Info(msg string, ctx ...interface{}) {
func (s silentLogger) Info(msg string, ctx ...any) {
s.Logger.Debug(msg, ctx...)
}
func (s silentLogger) Error(msg string, ctx ...interface{}) {
func (s silentLogger) Error(msg string, ctx ...any) {
s.Logger.Debug(msg, ctx...)
}
6 changes: 3 additions & 3 deletions control/beaconing/writer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func TestRegistrarRun(t *testing.T) {

g := graph.NewDefaultGraph(mctrl)
segProvider.EXPECT().SegmentsToRegister(gomock.Any(), test.segType).DoAndReturn(
func(_, _ interface{}) ([]beacon.Beacon, error) {
func(_, _ any) ([]beacon.Beacon, error) {
res := make([]beacon.Beacon, 0, len(test.beacons))
for _, desc := range test.beacons {
res = append(res, testBeacon(g, desc))
Expand Down Expand Up @@ -210,7 +210,7 @@ func TestRegistrarRun(t *testing.T) {

g := graph.NewDefaultGraph(mctrl)
segProvider.EXPECT().SegmentsToRegister(gomock.Any(), test.segType).DoAndReturn(
func(_, _ interface{}) ([]beacon.Beacon, error) {
func(_, _ any) ([]beacon.Beacon, error) {
res := make([]beacon.Beacon, len(test.beacons))
for _, desc := range test.beacons {
res = append(res, testBeacon(g, desc))
Expand Down Expand Up @@ -313,7 +313,7 @@ func TestRegistrarRun(t *testing.T) {
require.NoError(t, err)
segProvider.EXPECT().SegmentsToRegister(gomock.Any(),
seg.TypeDown).DoAndReturn(
func(_, _ interface{}) (<-chan beacon.Beacon, error) {
func(_, _ any) (<-chan beacon.Beacon, error) {
res := make(chan beacon.Beacon, 1)
b := testBeacon(g, []uint16{graph.If_120_X_111_B})
b.InIfID = 10
Expand Down
2 changes: 1 addition & 1 deletion daemon/internal/servers/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func (s *DaemonServer) fetchPaths(
) ([]snet.Path, error) {

r, err, _ := group.Do(fmt.Sprintf("%s%s%t", src, dst, refresh),
func() (interface{}, error) {
func() (any, error) {
return s.Fetcher.GetPaths(ctx, src, dst, refresh)
},
)
Expand Down
4 changes: 2 additions & 2 deletions gateway/control/sessionmonitor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ type pktMatcher struct {
}

// Matches returns whether x is a match.
func (m pktMatcher) Matches(x interface{}) bool {
func (m pktMatcher) Matches(x any) bool {
other, ok := x.([]byte)
if !ok {
return false
Expand All @@ -69,7 +69,7 @@ type udpAddrMatcher struct {
}

// Matches returns whether x is a match.
func (m udpAddrMatcher) Matches(x interface{}) bool {
func (m udpAddrMatcher) Matches(x any) bool {
other, ok := x.(*snet.UDPAddr)
if !ok {
return false
Expand Down
14 changes: 7 additions & 7 deletions gateway/control/watcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,14 @@ func TestGatewayWatcherRun(t *testing.T) {
fetcher.EXPECT().Close().AnyTimes().Return(nil)

discoverer.EXPECT().Gateways(gomock.Any()).DoAndReturn(
func(interface{}) ([]control.Gateway, error) {
func(any) ([]control.Gateway, error) {
discoveryCounts.Add(1)
return []control.Gateway{gateway1, gateway2}, nil
},
)

fetcher.EXPECT().Prefixes(gomock.Any(), gomock.Any()).AnyTimes().DoAndReturn(
func(_ interface{}, g *net.UDPAddr) ([]*net.IPNet, error) {
func(_ any, g *net.UDPAddr) ([]*net.IPNet, error) {
fetcherCounts.With("gateway", g.String()).Add(1)
return nil, serrors.New("error")
},
Expand Down Expand Up @@ -105,7 +105,7 @@ func TestGatewayWatcherRun(t *testing.T) {

// now let's reset and remove one gateway, this time we only return gateway1
discoverer.EXPECT().Gateways(gomock.Any()).DoAndReturn(
func(interface{}) ([]control.Gateway, error) {
func(any) ([]control.Gateway, error) {
discoveryCounts.Add(1)
return []control.Gateway{gateway1}, nil
},
Expand Down Expand Up @@ -144,26 +144,26 @@ func TestPrefixWatcherRun(t *testing.T) {
// called with the up to date list.
first := []*net.IPNet{cidr(t, "127.0.0.0/24"), cidr(t, "127.0.1.0/24"), cidr(t, "::/64")}
fetcher.EXPECT().Prefixes(gomock.Any(), gateway.Control).DoAndReturn(
func(_, _ interface{}) ([]*net.IPNet, error) {
func(_, _ any) ([]*net.IPNet, error) {
fetcherCounts.Add(1)
return first, nil
},
)
consumer.EXPECT().Prefixes(gomock.Any(), gateway, first).Do(
func(_, _, _ interface{}) {
func(_, _, _ any) {
consumerCounts.Add(1)
},
)

afterwards := []*net.IPNet{cidr(t, "127.0.0.0/24"), cidr(t, "::/64")}
fetcher.EXPECT().Prefixes(gomock.Any(), gateway.Control).AnyTimes().DoAndReturn(
func(_, _ interface{}) ([]*net.IPNet, error) {
func(_, _ any) ([]*net.IPNet, error) {
fetcherCounts.Add(1)
return afterwards, nil
},
)
consumer.EXPECT().Prefixes(gomock.Any(), gateway, afterwards).AnyTimes().Do(
func(_, _, _ interface{}) {
func(_, _, _ any) {
consumerCounts.Add(1)
},
)
Expand Down
2 changes: 1 addition & 1 deletion gateway/dataplane/framebuf.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ func (fb *frameBuf) String() string {
}

func initFreeFrames() {
freeFrames = ringbuf.New(freeFramesCap, func() interface{} {
freeFrames = ringbuf.New(freeFramesCap, func() any {
return newFrameBuf()
}, "ingress_free")
}
2 changes: 1 addition & 1 deletion gateway/dataplane/ipforwarder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ type packetMatcher struct {
packet gopacket.Packet
}

func (pm *packetMatcher) Matches(x interface{}) bool {
func (pm *packetMatcher) Matches(x any) bool {
packet := x.(gopacket.Packet)
return bytes.Equal(packet.Data(), pm.packet.Data())
}
Expand Down
2 changes: 1 addition & 1 deletion gateway/dataplane/routingtable_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import (

func TestRoutingTable(t *testing.T) {
rt := &dataplane.RoutingTable{}
_, ok := interface{}(rt).(control.RoutingTable)
_, ok := any(rt).(control.RoutingTable)
if ok != true {
assert.Fail(t, "should implement the client interface")
}
Expand Down
2 changes: 1 addition & 1 deletion gateway/dataplane/sender_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (

func expectFrames(conn *mock_net.MockPacketConn) *gomock.Call {
return conn.EXPECT().WriteTo(gomock.Any(), gomock.Any()).DoAndReturn(
func(f []byte, _ interface{}) (int, error) {
func(f []byte, _ any) (int, error) {
// Slow down the sending to induce packet batching.
time.Sleep(10 * time.Millisecond)
return 0, nil
Expand Down
2 changes: 1 addition & 1 deletion gateway/dataplane/session_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func createSession(t *testing.T, ctrl *gomock.Controller, frameChan chan []byte)
&snet.UDPAddr{Host: &net.UDPAddr{IP: net.IP{192, 168, 1, 1}}},
).AnyTimes()
conn.EXPECT().WriteTo(gomock.Any(), gomock.Any()).DoAndReturn(
func(f []byte, _ interface{}) (int, error) {
func(f []byte, _ any) (int, error) {
frameChan <- f
return 0, nil
}).AnyTimes()
Expand Down
4 changes: 2 additions & 2 deletions gateway/pktcls/class.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,11 @@ func (cm *ClassMap) UnmarshalJSON(b []byte) error {
return nil
}

func (cm ClassMap) MarshalYAML() (interface{}, error) {
func (cm ClassMap) MarshalYAML() (any, error) {
return (map[string]*Class)(cm), nil
}

func (cm *ClassMap) UnmarshalYAML(unmarshal func(interface{}) error) error {
func (cm *ClassMap) UnmarshalYAML(unmarshal func(any) error) error {
err := unmarshal(cm)
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion gateway/pktcls/error_listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ type ErrorListener struct {
errorType string
}

func (l *ErrorListener) SyntaxError(recognizer antlr.Recognizer, offendingSymbol interface{}, line,
func (l *ErrorListener) SyntaxError(recognizer antlr.Recognizer, offendingSymbol any, line,
column int, msg string, e antlr.RecognitionException) {
l.msg = msg
log.Debug(fmt.Sprintf("%s Error", l.errorType), "err", msg)
Expand Down
2 changes: 1 addition & 1 deletion gateway/pktcls/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ const (
)

// generic container for marshaling custom data
type jsonContainer map[string]interface{}
type jsonContainer map[string]any

func marshalInterface(t Typer) ([]byte, error) {
return json.Marshal(jsonContainer{t.Type(): t})
Expand Down
2 changes: 1 addition & 1 deletion pkg/experimental/hiddenpath/beaconwriter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ type addrMatcher struct {
udp *snet.UDPAddr
}

func (m addrMatcher) Matches(other interface{}) bool {
func (m addrMatcher) Matches(other any) bool {
if m.svc != nil {
svc, ok := other.(*snet.SVCAddr)
if !ok {
Expand Down
4 changes: 2 additions & 2 deletions pkg/experimental/hiddenpath/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ func (g Groups) Validate() error {
}

// UnmarshalYAML implements the yaml unmarshaller for the Groups type.
func (g Groups) UnmarshalYAML(unmarshal func(interface{}) error) error {
func (g Groups) UnmarshalYAML(unmarshal func(any) error) error {
yg := &registrationPolicyInfo{}
if err := unmarshal(&yg); err != nil {
return serrors.Wrap("unmarshaling YAML", err)
Expand All @@ -171,7 +171,7 @@ func (g Groups) UnmarshalYAML(unmarshal func(interface{}) error) error {
}

// MarshalYAML implements yaml marshalling.
func (g Groups) MarshalYAML() (interface{}, error) {
func (g Groups) MarshalYAML() (any, error) {
return &registrationPolicyInfo{
Groups: marshalGroups(g),
}, nil
Expand Down
4 changes: 2 additions & 2 deletions pkg/experimental/hiddenpath/registrationpolicy.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func (p RegistrationPolicy) Validate() error {
}

// MarshalYAML implements the yaml marshaller interface.
func (p RegistrationPolicy) MarshalYAML() (interface{}, error) {
func (p RegistrationPolicy) MarshalYAML() (any, error) {
collectedGroups := make(Groups)
policies := make(map[uint64][]string, len(p))
for ifID, ip := range p {
Expand All @@ -68,7 +68,7 @@ func (p RegistrationPolicy) MarshalYAML() (interface{}, error) {
}

// UnmarshalYAML implements YAML unmarshaling for the registration policy type.
func (p RegistrationPolicy) UnmarshalYAML(unmarshal func(interface{}) error) error {
func (p RegistrationPolicy) UnmarshalYAML(unmarshal func(any) error) error {
rawPolicy := &registrationPolicyInfo{}
if err := unmarshal(&rawPolicy); err != nil {
return serrors.Wrap("parsing yaml", err)
Expand Down
12 changes: 6 additions & 6 deletions pkg/grpc/interceptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func LogIDClientInterceptor() grpc.UnaryClientInterceptor {
return func(
ctx context.Context,
method string,
req, resp interface{},
req, resp any,
cc *grpc.ClientConn,
invoker grpc.UnaryInvoker,
opts ...grpc.CallOption,
Expand Down Expand Up @@ -65,10 +65,10 @@ func LogIDClientStreamInterceptor() grpc.StreamClientInterceptor {
func LogIDServerInterceptor() grpc.UnaryServerInterceptor {
return func(
ctx context.Context,
req interface{},
req any,
info *grpc.UnaryServerInfo,
handler grpc.UnaryHandler,
) (interface{}, error) {
) (any, error) {

logger := loggerFromSpan(opentracing.SpanFromContext(ctx))
logger.Debug("Serving RPC", "method", info.FullMethod)
Expand All @@ -79,7 +79,7 @@ func LogIDServerInterceptor() grpc.UnaryServerInterceptor {

func LogIDServerStreamInterceptor() grpc.StreamServerInterceptor {
return func(
srv interface{},
srv any,
ss grpc.ServerStream,
info *grpc.StreamServerInfo,
handler grpc.StreamHandler,
Expand Down Expand Up @@ -116,7 +116,7 @@ func openTracingInterceptorWithTarget() grpc.UnaryClientInterceptor {
return func(
ctx context.Context,
method string,
req, reply interface{},
req, reply any,
cc *grpc.ClientConn,
invoker grpc.UnaryInvoker,
opts ...grpc.CallOption,
Expand All @@ -125,7 +125,7 @@ func openTracingInterceptorWithTarget() grpc.UnaryClientInterceptor {
spanDecorator := func(
span opentracing.Span,
method string,
req, resp interface{},
req, resp any,
grpcError error,
) {
if span != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/log/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func FromCtx(ctx context.Context) Logger {

// WithLabels returns context with additional labels added to the logger.
// For convenience it also returns the logger itself.
func WithLabels(ctx context.Context, labels ...interface{}) (context.Context, Logger) {
func WithLabels(ctx context.Context, labels ...any) (context.Context, Logger) {
logger := FromCtx(ctx).New(labels...)
ctx = CtxWith(ctx, logger)
return ctx, logger
Expand Down
8 changes: 4 additions & 4 deletions pkg/log/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,15 +221,15 @@ func (l httpLevel) ServeHTTP(w http.ResponseWriter, r *http.Request) {

// SafeNewLogger creates a new logger as a child of l only if l is not nil. If l is nil, then
// nil is returned.
func SafeNewLogger(l Logger, fields ...interface{}) Logger {
func SafeNewLogger(l Logger, fields ...any) Logger {
if l != nil {
return l.New(fields...)
}
return nil
}

// SafeDebug logs to l only if l is not nil.
func SafeDebug(l Logger, msg string, fields ...interface{}) {
func SafeDebug(l Logger, msg string, fields ...any) {
if l != nil {
if ll, ok := l.(*logger); ok {
ll.logger.Debug(msg, convertCtx(fields)...)
Expand All @@ -240,7 +240,7 @@ func SafeDebug(l Logger, msg string, fields ...interface{}) {
}

// SafeInfo logs to l only if l is not nil.
func SafeInfo(l Logger, msg string, fields ...interface{}) {
func SafeInfo(l Logger, msg string, fields ...any) {
if l != nil {
if ll, ok := l.(*logger); ok {
ll.logger.Info(msg, convertCtx(fields)...)
Expand All @@ -251,7 +251,7 @@ func SafeInfo(l Logger, msg string, fields ...interface{}) {
}

// SafeError logs to l only if l is not nil.
func SafeError(l Logger, msg string, fields ...interface{}) {
func SafeError(l Logger, msg string, fields ...any) {
if l != nil {
if ll, ok := l.(*logger); ok {
ll.logger.Error(msg, convertCtx(fields)...)
Expand Down
Loading

0 comments on commit c78197f

Please sign in to comment.