chore: replace interface{} with any

This commit is contained in:
Vincent Bernat
2025-07-29 07:37:42 +02:00
parent 10dfefebb4
commit 18beb310ee
61 changed files with 315 additions and 315 deletions

View File

@@ -12,9 +12,9 @@ import (
) )
// StartStopComponents activate/deactivate components in order. // StartStopComponents activate/deactivate components in order.
func StartStopComponents(r *reporter.Reporter, daemonComponent daemon.Component, otherComponents []interface{}) error { func StartStopComponents(r *reporter.Reporter, daemonComponent daemon.Component, otherComponents []any) error {
components := append([]interface{}{r, daemonComponent}, otherComponents...) components := append([]any{r, daemonComponent}, otherComponents...)
startedComponents := []interface{}{} startedComponents := []any{}
defer func() { defer func() {
for _, cmp := range startedComponents { for _, cmp := range startedComponents {
if stopperC, ok := cmp.(stopper); ok { if stopperC, ok := cmp.(stopper); ok {
@@ -30,7 +30,7 @@ func StartStopComponents(r *reporter.Reporter, daemonComponent daemon.Component,
return fmt.Errorf("unable to start component: %w", err) return fmt.Errorf("unable to start component: %w", err)
} }
} }
startedComponents = append([]interface{}{cmp}, startedComponents...) startedComponents = append([]any{cmp}, startedComponents...)
} }
r.Info(). r.Info().

View File

@@ -55,7 +55,7 @@ func (c ComponentStartError) Start() error {
func TestStartStopError(t *testing.T) { func TestStartStopError(t *testing.T) {
r := reporter.NewMock(t) r := reporter.NewMock(t)
daemonComponent := daemon.NewMock(t) daemonComponent := daemon.NewMock(t)
otherComponents := []interface{}{ otherComponents := []any{
&ComponentStartStop{}, &ComponentStartStop{},
&ComponentStop{}, &ComponentStop{},
&ComponentStart{}, &ComponentStart{},
@@ -67,7 +67,7 @@ func TestStartStopError(t *testing.T) {
t.Error("StartStopComponents() did not trigger an error") t.Error("StartStopComponents() did not trigger an error")
} }
expected := []interface{}{ expected := []any{
&ComponentStartStop{ &ComponentStartStop{
Startable: Startable{Started: true}, Startable: Startable{Started: true},
Stopable: Stopable{Stopped: true}, Stopable: Stopable{Stopped: true},
@@ -90,7 +90,7 @@ func TestStartStopError(t *testing.T) {
func TestStartStop(t *testing.T) { func TestStartStop(t *testing.T) {
r := reporter.NewMock(t) r := reporter.NewMock(t)
daemonComponent := daemon.NewMock(t) daemonComponent := daemon.NewMock(t)
otherComponents := []interface{}{ otherComponents := []any{
&ComponentStartStop{}, &ComponentStartStop{},
&ComponentStop{}, &ComponentStop{},
&ComponentStart{}, &ComponentStart{},
@@ -104,7 +104,7 @@ func TestStartStop(t *testing.T) {
t.Errorf("StartStopComponents() error:\n%+v", err) t.Errorf("StartStopComponents() error:\n%+v", err)
} }
expected := []interface{}{ expected := []any{
&ComponentStartStop{ &ComponentStartStop{
Startable: Startable{Started: true}, Startable: Startable{Started: true},
Stopable: Stopable{Stopped: true}, Stopable: Stopable{Stopped: true},

View File

@@ -35,7 +35,7 @@ type ConfigRelatedOptions struct {
// Parse parses the configuration file (if present) and the // Parse parses the configuration file (if present) and the
// environment variables into the provided configuration. // environment variables into the provided configuration.
func (c ConfigRelatedOptions) Parse(out io.Writer, component string, config interface{}) error { func (c ConfigRelatedOptions) Parse(out io.Writer, component string, config any) error {
var rawConfig gin.H var rawConfig gin.H
if cfgFile := c.Path; cfgFile != "" { if cfgFile := c.Path; cfgFile != "" {
if strings.HasPrefix(cfgFile, "http://") || strings.HasPrefix(cfgFile, "https://") { if strings.HasPrefix(cfgFile, "http://") || strings.HasPrefix(cfgFile, "https://") {
@@ -112,11 +112,11 @@ func (c ConfigRelatedOptions) Parse(out io.Writer, component string, config inte
// build a map "squid -> purple -> quirk -> // build a map "squid -> purple -> quirk ->
// 47". From AKVORADO_CFG_CMP_SQUID_3_PURPLE=47, we // 47". From AKVORADO_CFG_CMP_SQUID_3_PURPLE=47, we
// build "squid[3] -> purple -> 47" // build "squid[3] -> purple -> 47"
var rawConfig interface{} var rawConfig any
rawConfig = kv[1] rawConfig = kv[1]
for i := len(kk) - 1; i > 2; i-- { for i := len(kk) - 1; i > 2; i-- {
if index, err := strconv.Atoi(kk[i]); err == nil { if index, err := strconv.Atoi(kk[i]); err == nil {
newRawConfig := make([]interface{}, index+1) newRawConfig := make([]any, index+1)
newRawConfig[index] = rawConfig newRawConfig[index] = rawConfig
rawConfig = newRawConfig rawConfig = newRawConfig
} else { } else {
@@ -171,7 +171,7 @@ func (c ConfigRelatedOptions) Parse(out io.Writer, component string, config inte
// the Reset() method if present. // the Reset() method if present.
func DefaultHook() (mapstructure.DecodeHookFunc, func()) { func DefaultHook() (mapstructure.DecodeHookFunc, func()) {
disabled := false disabled := false
hook := func(from, to reflect.Value) (interface{}, error) { hook := func(from, to reflect.Value) (any, error) {
if disabled { if disabled {
return from.Interface(), nil return from.Interface(), nil
} }
@@ -217,7 +217,7 @@ func DefaultHook() (mapstructure.DecodeHookFunc, func()) {
// non-nil slice. Like DefaultHook, it can be disabled. // non-nil slice. Like DefaultHook, it can be disabled.
func ZeroSliceHook() (mapstructure.DecodeHookFunc, func()) { func ZeroSliceHook() (mapstructure.DecodeHookFunc, func()) {
disabled := false disabled := false
hook := func(from, to reflect.Value) (interface{}, error) { hook := func(from, to reflect.Value) (any, error) {
if disabled { if disabled {
return from.Interface(), nil return from.Interface(), nil
} }

View File

@@ -170,7 +170,7 @@ module2:
"workers": 5, "workers": 5,
"intervalvalue": "20m0s", "intervalvalue": "20m0s",
}, },
"elements": []interface{}{ "elements": []any{
gin.H{ gin.H{
"name": "first", "name": "first",
"gauge": 67, "gauge": 67,
@@ -356,7 +356,7 @@ invalid key "unused"`); diff != "" {
} }
func TestDefaultInSlice(t *testing.T) { func TestDefaultInSlice(t *testing.T) {
try := func(t *testing.T, parse func(cmd.ConfigRelatedOptions, *bytes.Buffer) interface{}) { try := func(t *testing.T, parse func(cmd.ConfigRelatedOptions, *bytes.Buffer) any) {
// Configuration file // Configuration file
config := `--- config := `---
modules: modules:
@@ -434,7 +434,7 @@ modules:
} }
} }
t.Run("without pointer", func(t *testing.T) { t.Run("without pointer", func(t *testing.T) {
try(t, func(c cmd.ConfigRelatedOptions, out *bytes.Buffer) interface{} { try(t, func(c cmd.ConfigRelatedOptions, out *bytes.Buffer) any {
parsed := struct { parsed := struct {
Modules []dummyConfiguration Modules []dummyConfiguration
}{} }{}
@@ -445,7 +445,7 @@ modules:
}) })
}) })
t.Run("with pointer", func(t *testing.T) { t.Run("with pointer", func(t *testing.T) {
try(t, func(c cmd.ConfigRelatedOptions, out *bytes.Buffer) interface{} { try(t, func(c cmd.ConfigRelatedOptions, out *bytes.Buffer) any {
parsed := struct { parsed := struct {
Modules []*dummyConfiguration Modules []*dummyConfiguration
}{} }{}

View File

@@ -51,7 +51,7 @@ containers started with the label "akvorado.conntrack.fix=1".`,
addCommonHTTPHandlers(r, "conntrack-fixer", httpComponent) addCommonHTTPHandlers(r, "conntrack-fixer", httpComponent)
versionMetrics(r) versionMetrics(r)
components := []interface{}{ components := []any{
httpComponent, httpComponent,
conntrackFixerComponent, conntrackFixerComponent,
} }

View File

@@ -131,7 +131,7 @@ func consoleStart(r *reporter.Reporter, config ConsoleConfiguration, checkOnly b
} }
// Start all the components. // Start all the components.
components := []interface{}{ components := []any{
httpComponent, httpComponent,
clickhouseComponent, clickhouseComponent,
authenticationComponent, authenticationComponent,

View File

@@ -124,7 +124,7 @@ func demoExporterStart(r *reporter.Reporter, config DemoExporterConfiguration, c
} }
// Start all the components. // Start all the components.
components := []interface{}{ components := []any{
httpComponent, httpComponent,
snmpComponent, snmpComponent,
bmpComponent, bmpComponent,

View File

@@ -108,7 +108,7 @@ func inletStart(r *reporter.Reporter, config InletConfiguration, checkOnly bool)
} }
// Start all the components. // Start all the components.
components := []interface{}{ components := []any{
httpComponent, httpComponent,
kafkaComponent, kafkaComponent,
flowComponent, flowComponent,

View File

@@ -42,7 +42,7 @@ func TestOrchestratorConfig(t *testing.T) {
t.Fatalf("ReadFile() error:\n%+v", err) t.Fatalf("ReadFile() error:\n%+v", err)
} }
var expectedYAML struct { var expectedYAML struct {
Paths map[string]interface{} `yaml:"paths"` Paths map[string]any `yaml:"paths"`
} }
if err := yaml.Unmarshal(expected, &expectedYAML); err != nil { if err := yaml.Unmarshal(expected, &expectedYAML); err != nil {
t.Fatalf("yaml.Unmarshal(expected) error:\n%+v", err) t.Fatalf("yaml.Unmarshal(expected) error:\n%+v", err)
@@ -57,30 +57,30 @@ func TestOrchestratorConfig(t *testing.T) {
if err := root.Execute(); err != nil { if err := root.Execute(); err != nil {
t.Fatalf("`orchestrator` command error:\n%+v", err) t.Fatalf("`orchestrator` command error:\n%+v", err)
} }
var gotYAML map[string]interface{} var gotYAML map[string]any
if err := yaml.Unmarshal(buf.Bytes(), &gotYAML); err != nil { if err := yaml.Unmarshal(buf.Bytes(), &gotYAML); err != nil {
t.Fatalf("yaml.Unmarshal(output) error:\n%+v", err) t.Fatalf("yaml.Unmarshal(output) error:\n%+v", err)
} }
for path, expected := range expectedYAML.Paths { for path, expected := range expectedYAML.Paths {
var got interface{} var got any
got = gotYAML got = gotYAML
i := 0 i := 0
for _, component := range strings.Split(path, ".") { for _, component := range strings.Split(path, ".") {
var ok bool var ok bool
i++ i++
switch gotConcrete := got.(type) { switch gotConcrete := got.(type) {
case []interface{}: case []any:
index, err := strconv.Atoi(component) index, err := strconv.Atoi(component)
if err != nil { if err != nil {
t.Fatalf("key %q at level %d should be an int", path, i) t.Fatalf("key %q at level %d should be an int", path, i)
} }
got = gotConcrete[index] got = gotConcrete[index]
case map[interface{}]interface{}: case map[any]any:
got, ok = gotConcrete[component] got, ok = gotConcrete[component]
if !ok { if !ok {
t.Fatalf("key %q does not exist in result", path) t.Fatalf("key %q does not exist in result", path)
} }
case map[string]interface{}: case map[string]any:
got, ok = gotConcrete[component] got, ok = gotConcrete[component]
if !ok { if !ok {
t.Fatalf("key %q does not exist in result", path) t.Fatalf("key %q does not exist in result", path)

View File

@@ -188,7 +188,7 @@ func outletStart(r *reporter.Reporter, config OutletConfiguration, checkOnly boo
// OutletConfigurationUnmarshallerHook renames SNMP configuration to metadata and // OutletConfigurationUnmarshallerHook renames SNMP configuration to metadata and
// BMP configuration to routing. // BMP configuration to routing.
func OutletConfigurationUnmarshallerHook() mapstructure.DecodeHookFunc { func OutletConfigurationUnmarshallerHook() mapstructure.DecodeHookFunc {
return func(from, to reflect.Value) (interface{}, error) { return func(from, to reflect.Value) (any, error) {
if from.Kind() != reflect.Map || from.IsNil() || to.Type() != reflect.TypeOf(OutletConfiguration{}) { if from.Kind() != reflect.Map || from.IsNil() || to.Type() != reflect.TypeOf(OutletConfiguration{}) {
return from.Interface(), nil return from.Interface(), nil
} }

View File

@@ -58,7 +58,7 @@ func TestMock(t *testing.T) {
Return(mockRows, nil) Return(mockRows, nil)
mockRows.EXPECT().Next().Return(true) mockRows.EXPECT().Next().Return(true)
mockRows.EXPECT().Close() mockRows.EXPECT().Close()
mockRows.EXPECT().Scan(gomock.Any()).DoAndReturn(func(args ...interface{}) interface{} { mockRows.EXPECT().Scan(gomock.Any()).DoAndReturn(func(args ...any) any {
arg0 := args[0].(*uint64) arg0 := args[0].(*uint64)
*arg0 = uint64(10) *arg0 = uint64(10)
arg1 := args[1].(*uint64) arg1 := args[1].(*uint64)

View File

@@ -75,7 +75,7 @@ func SameTypeOrSuperset(input, ref reflect.Type) bool {
// GetMapStructureDecoderConfig returns a decoder config for // GetMapStructureDecoderConfig returns a decoder config for
// mapstructure with all registered hooks as well as appropriate // mapstructure with all registered hooks as well as appropriate
// default configuration. // default configuration.
func GetMapStructureDecoderConfig(config interface{}, hooks ...mapstructure.DecodeHookFunc) *mapstructure.DecoderConfig { func GetMapStructureDecoderConfig(config any, hooks ...mapstructure.DecodeHookFunc) *mapstructure.DecoderConfig {
return &mapstructure.DecoderConfig{ return &mapstructure.DecoderConfig{
Result: config, Result: config,
ErrorUnused: true, ErrorUnused: true,
@@ -99,8 +99,8 @@ func StringToSliceHookFunc(sep string) mapstructure.DecodeHookFunc {
return func( return func(
f reflect.Kind, f reflect.Kind,
t reflect.Kind, t reflect.Kind,
data interface{}, data any,
) (interface{}, error) { ) (any, error) {
if f != reflect.String || t != reflect.Slice { if f != reflect.String || t != reflect.Slice {
return data, nil return data, nil
} }
@@ -116,7 +116,7 @@ func StringToSliceHookFunc(sep string) mapstructure.DecodeHookFunc {
// ProtectedDecodeHookFunc wraps a DecodeHookFunc to recover and returns an error on panic. // ProtectedDecodeHookFunc wraps a DecodeHookFunc to recover and returns an error on panic.
func ProtectedDecodeHookFunc(hook mapstructure.DecodeHookFunc) mapstructure.DecodeHookFunc { func ProtectedDecodeHookFunc(hook mapstructure.DecodeHookFunc) mapstructure.DecodeHookFunc {
return func(from, to reflect.Value) (v interface{}, err error) { return func(from, to reflect.Value) (v any, err error) {
defer func() { defer func() {
if r := recover(); r != nil { if r := recover(); r != nil {
v = nil v = nil
@@ -137,7 +137,7 @@ func MapStructureMatchName(mapKey, fieldName string) bool {
// DefaultValuesUnmarshallerHook adds default values from the provided // DefaultValuesUnmarshallerHook adds default values from the provided
// configuration. For each missing non-default key, it will add them. // configuration. For each missing non-default key, it will add them.
func DefaultValuesUnmarshallerHook[Configuration any](defaultConfiguration Configuration) mapstructure.DecodeHookFunc { func DefaultValuesUnmarshallerHook[Configuration any](defaultConfiguration Configuration) mapstructure.DecodeHookFunc {
return func(from, to reflect.Value) (interface{}, error) { return func(from, to reflect.Value) (any, error) {
from = ElemOrIdentity(from) from = ElemOrIdentity(from)
to = ElemOrIdentity(to) to = ElemOrIdentity(to)
if to.Type() != reflect.TypeOf(defaultConfiguration) { if to.Type() != reflect.TypeOf(defaultConfiguration) {
@@ -180,7 +180,7 @@ func DefaultValuesUnmarshallerHook[Configuration any](defaultConfiguration Confi
// RenameKeyUnmarshallerHook move a configuration setting from one place to another. // RenameKeyUnmarshallerHook move a configuration setting from one place to another.
func RenameKeyUnmarshallerHook[Configuration any](zeroConfiguration Configuration, fromLabel, toLabel string) mapstructure.DecodeHookFunc { func RenameKeyUnmarshallerHook[Configuration any](zeroConfiguration Configuration, fromLabel, toLabel string) mapstructure.DecodeHookFunc {
return func(from, to reflect.Value) (interface{}, error) { return func(from, to reflect.Value) (any, error) {
if from.Kind() != reflect.Map || from.IsNil() || to.Type() != reflect.TypeOf(zeroConfiguration) { if from.Kind() != reflect.Map || from.IsNil() || to.Type() != reflect.TypeOf(zeroConfiguration) {
return from.Interface(), nil return from.Interface(), nil
} }
@@ -218,7 +218,7 @@ func RenameKeyUnmarshallerHook[Configuration any](zeroConfiguration Configuratio
// type. A map from configuration types to a function providing the inner // type. A map from configuration types to a function providing the inner
// default config should be provided. // default config should be provided.
func ParametrizedConfigurationUnmarshallerHook[OuterConfiguration any, InnerConfiguration any](zeroOuterConfiguration OuterConfiguration, innerConfigurationMap map[string](func() InnerConfiguration)) mapstructure.DecodeHookFunc { func ParametrizedConfigurationUnmarshallerHook[OuterConfiguration any, InnerConfiguration any](zeroOuterConfiguration OuterConfiguration, innerConfigurationMap map[string](func() InnerConfiguration)) mapstructure.DecodeHookFunc {
return func(from, to reflect.Value) (interface{}, error) { return func(from, to reflect.Value) (any, error) {
if to.Type() != reflect.TypeOf(zeroOuterConfiguration) { if to.Type() != reflect.TypeOf(zeroOuterConfiguration) {
return from.Interface(), nil return from.Interface(), nil
} }
@@ -306,7 +306,7 @@ func ParametrizedConfigurationUnmarshallerHook[OuterConfiguration any, InnerConf
} }
// ParametrizedConfigurationMarshalYAML undoes ParametrizedConfigurationUnmarshallerHook(). // ParametrizedConfigurationMarshalYAML undoes ParametrizedConfigurationUnmarshallerHook().
func ParametrizedConfigurationMarshalYAML[OuterConfiguration any, InnerConfiguration any](oc OuterConfiguration, innerConfigurationMap map[string](func() InnerConfiguration)) (interface{}, error) { func ParametrizedConfigurationMarshalYAML[OuterConfiguration any, InnerConfiguration any](oc OuterConfiguration, innerConfigurationMap map[string](func() InnerConfiguration)) (any, error) {
var innerConfigStruct reflect.Value var innerConfigStruct reflect.Value
outerConfigStruct := ElemOrIdentity(reflect.ValueOf(oc)) outerConfigStruct := ElemOrIdentity(reflect.ValueOf(oc))
result := gin.H{} result := gin.H{}

View File

@@ -44,8 +44,8 @@ func TestStringToSliceHookFunc(t *testing.T) {
} }
TestConfigurationDecode(t, ConfigurationDecodeCases{ TestConfigurationDecode(t, ConfigurationDecodeCases{
{ {
Initial: func() interface{} { return Configuration{} }, Initial: func() any { return Configuration{} },
Configuration: func() interface{} { Configuration: func() any {
return gin.H{ return gin.H{
"a": "blip,blop", "a": "blip,blop",
"b": "1,2,3,4", "b": "1,2,3,4",
@@ -64,7 +64,7 @@ func TestProtectedDecodeHook(t *testing.T) {
A string A string
B string B string
} }
panicHook := func(from, _ reflect.Type, data interface{}) (interface{}, error) { panicHook := func(from, _ reflect.Type, data any) (any, error) {
if from.Kind() == reflect.String { if from.Kind() == reflect.String {
panic(errors.New("noooo")) panic(errors.New("noooo"))
} }
@@ -106,8 +106,8 @@ func TestDefaultValuesConfig(t *testing.T) {
})) }))
TestConfigurationDecode(t, ConfigurationDecodeCases{ TestConfigurationDecode(t, ConfigurationDecodeCases{
{ {
Initial: func() interface{} { return OuterConfiguration{} }, Initial: func() any { return OuterConfiguration{} },
Configuration: func() interface{} { Configuration: func() any {
return gin.H{ return gin.H{
"dd": []gin.H{ "dd": []gin.H{
{ {
@@ -150,8 +150,8 @@ func TestRenameConfig(t *testing.T) {
TestConfigurationDecode(t, ConfigurationDecodeCases{ TestConfigurationDecode(t, ConfigurationDecodeCases{
{ {
Description: "no rename needed", Description: "no rename needed",
Initial: func() interface{} { return Configuration{} }, Initial: func() any { return Configuration{} },
Configuration: func() interface{} { Configuration: func() any {
return gin.H{ return gin.H{
"unchanged-label": "hello", "unchanged-label": "hello",
"new-label": "bye", "new-label": "bye",
@@ -163,8 +163,8 @@ func TestRenameConfig(t *testing.T) {
}, },
}, { }, {
Description: "rename needed", Description: "rename needed",
Initial: func() interface{} { return Configuration{} }, Initial: func() any { return Configuration{} },
Configuration: func() interface{} { Configuration: func() any {
return gin.H{ return gin.H{
"unchanged-label": "hello", "unchanged-label": "hello",
"old-label": "bye", "old-label": "bye",
@@ -176,8 +176,8 @@ func TestRenameConfig(t *testing.T) {
}, },
}, { }, {
Description: "conflicts", Description: "conflicts",
Initial: func() interface{} { return Configuration{} }, Initial: func() any { return Configuration{} },
Configuration: func() interface{} { Configuration: func() any {
return gin.H{ return gin.H{
"unchanged-label": "hello", "unchanged-label": "hello",
"old-label": "bye", "old-label": "bye",
@@ -201,16 +201,16 @@ func TestParametrizedConfig(t *testing.T) {
type OuterConfiguration struct { type OuterConfiguration struct {
AA string AA string
BB string BB string
Config interface{} Config any
} }
available := map[string](func() interface{}){ available := map[string](func() any){
"type1": func() interface{} { "type1": func() any {
return InnerConfigurationType1{ return InnerConfigurationType1{
CC: "cc1", CC: "cc1",
DD: "dd1", DD: "dd1",
} }
}, },
"type2": func() interface{} { "type2": func() any {
return InnerConfigurationType2{ return InnerConfigurationType2{
CC: "cc2", CC: "cc2",
EE: "ee2", EE: "ee2",
@@ -223,8 +223,8 @@ func TestParametrizedConfig(t *testing.T) {
TestConfigurationDecode(t, ConfigurationDecodeCases{ TestConfigurationDecode(t, ConfigurationDecodeCases{
{ {
Description: "type1", Description: "type1",
Initial: func() interface{} { return OuterConfiguration{} }, Initial: func() any { return OuterConfiguration{} },
Configuration: func() interface{} { Configuration: func() any {
return gin.H{ return gin.H{
"type": "type1", "type": "type1",
"aa": "a1", "aa": "a1",
@@ -243,8 +243,8 @@ func TestParametrizedConfig(t *testing.T) {
}, },
}, { }, {
Description: "type2", Description: "type2",
Initial: func() interface{} { return OuterConfiguration{} }, Initial: func() any { return OuterConfiguration{} },
Configuration: func() interface{} { Configuration: func() any {
return gin.H{ return gin.H{
"type": "type2", "type": "type2",
"aa": "a2", "aa": "a2",
@@ -263,8 +263,8 @@ func TestParametrizedConfig(t *testing.T) {
}, },
}, { }, {
Description: "unknown type", Description: "unknown type",
Initial: func() interface{} { return OuterConfiguration{} }, Initial: func() any { return OuterConfiguration{} },
Configuration: func() interface{} { Configuration: func() any {
return gin.H{ return gin.H{
"type": "type3", "type": "type3",
"aa": "a2", "aa": "a2",
@@ -345,8 +345,8 @@ func TestDeprecatedFields(t *testing.T) {
RegisterMapstructureDeprecatedFields[Configuration]("C", "D") RegisterMapstructureDeprecatedFields[Configuration]("C", "D")
TestConfigurationDecode(t, ConfigurationDecodeCases{ TestConfigurationDecode(t, ConfigurationDecodeCases{
{ {
Initial: func() interface{} { return Configuration{} }, Initial: func() any { return Configuration{} },
Configuration: func() interface{} { Configuration: func() any {
return gin.H{ return gin.H{
"a": "hello", "a": "hello",
"b": "bye", "b": "bye",
@@ -359,8 +359,8 @@ func TestDeprecatedFields(t *testing.T) {
B: "bye", B: "bye",
}, },
}, { }, {
Initial: func() interface{} { return Configuration{} }, Initial: func() any { return Configuration{} },
Configuration: func() interface{} { Configuration: func() any {
return gin.H{ return gin.H{
"a": "hello", "a": "hello",
"b": "bye", "b": "bye",

View File

@@ -161,7 +161,7 @@ func LooksLikeSubnetMap(v reflect.Value) (result bool) {
// valid networks are provided as key. It also accepts a single value // valid networks are provided as key. It also accepts a single value
// instead of a map for backward compatibility. // instead of a map for backward compatibility.
func SubnetMapUnmarshallerHook[V any]() mapstructure.DecodeHookFunc { func SubnetMapUnmarshallerHook[V any]() mapstructure.DecodeHookFunc {
return func(from, to reflect.Value) (interface{}, error) { return func(from, to reflect.Value) (any, error) {
if to.Type() != reflect.TypeOf(SubnetMap[V]{}) { if to.Type() != reflect.TypeOf(SubnetMap[V]{}) {
return from.Interface(), nil return from.Interface(), nil
} }
@@ -248,7 +248,7 @@ func SubnetMapParseKey(k string) (string, error) {
} }
// MarshalYAML turns a subnet into a map that can be marshaled. // MarshalYAML turns a subnet into a map that can be marshaled.
func (sm SubnetMap[V]) MarshalYAML() (interface{}, error) { func (sm SubnetMap[V]) MarshalYAML() (any, error) {
return sm.ToMap(), nil return sm.ToMap(), nil
} }

View File

@@ -19,10 +19,10 @@ func TestSubnetMapUnmarshalHook(t *testing.T) {
var nilMap map[string]string var nilMap map[string]string
cases := []struct { cases := []struct {
Description string Description string
Input interface{} Input any
Tests map[string]string Tests map[string]string
Error bool Error bool
YAML interface{} YAML any
}{ }{
{ {
Description: "nil", Description: "nil",

View File

@@ -79,7 +79,7 @@ func CheckExternalService(t *testing.T, name string, candidates []string) string
} }
// StartStop starts a component and stops it on cleanup. // StartStop starts a component and stops it on cleanup.
func StartStop(t *testing.T, component interface{}) { func StartStop(t *testing.T, component any) {
t.Helper() t.Helper()
if starterC, ok := component.(starter); ok { if starterC, ok := component.(starter); ok {
if err := starterC.Start(); err != nil { if err := starterC.Start(); err != nil {

View File

@@ -20,9 +20,9 @@ import (
type ConfigurationDecodeCases []struct { type ConfigurationDecodeCases []struct {
Description string Description string
Pos Pos Pos Pos
Initial func() interface{} // initial value for configuration Initial func() any // initial value for configuration
Configuration func() interface{} // configuration to decode Configuration func() any // configuration to decode
Expected interface{} Expected any
Error bool Error bool
SkipValidation bool SkipValidation bool
} }
@@ -41,7 +41,7 @@ func TestConfigurationDecode(t *testing.T, cases ConfigurationDecodeCases, optio
} }
t.Run(title, func(t *testing.T) { t.Run(title, func(t *testing.T) {
t.Helper() t.Helper()
var configuration interface{} var configuration any
if fromYAML { if fromYAML {
// Encode and decode with YAML // Encode and decode with YAML
out, err := yaml.Marshal(tc.Configuration()) out, err := yaml.Marshal(tc.Configuration())

View File

@@ -22,12 +22,12 @@ var prettyC = pretty.Config{
IncludeUnexported: false, IncludeUnexported: false,
} }
func formatByte(v interface{}) string { func formatByte(v any) string {
return fmt.Sprintf("0x%x", v) return fmt.Sprintf("0x%x", v)
} }
func defaultPrettyFormatters() map[reflect.Type]interface{} { func defaultPrettyFormatters() map[reflect.Type]any {
result := map[reflect.Type]interface{}{ result := map[reflect.Type]any{
reflect.TypeOf(net.IP{}): fmt.Sprint, reflect.TypeOf(net.IP{}): fmt.Sprint,
reflect.TypeOf(netip.Addr{}): fmt.Sprint, reflect.TypeOf(netip.Addr{}): fmt.Sprint,
reflect.TypeOf(time.Time{}): fmt.Sprint, reflect.TypeOf(time.Time{}): fmt.Sprint,
@@ -42,11 +42,11 @@ func defaultPrettyFormatters() map[reflect.Type]interface{} {
return result return result
} }
var nonDefaultPrettyFormatters = map[reflect.Type]interface{}{} var nonDefaultPrettyFormatters = map[reflect.Type]any{}
// AddPrettyFormatter add a global pretty formatter. We cannot put everything in // AddPrettyFormatter add a global pretty formatter. We cannot put everything in
// the default map due to cycles. // the default map due to cycles.
func AddPrettyFormatter(t reflect.Type, fn interface{}) { func AddPrettyFormatter(t reflect.Type, fn any) {
nonDefaultPrettyFormatters[t] = fn nonDefaultPrettyFormatters[t] = fn
} }
@@ -55,12 +55,12 @@ type DiffOption struct {
kind int kind int
// When this is a formatter // When this is a formatter
t reflect.Type t reflect.Type
fn interface{} fn any
} }
// Diff return a diff of two objects. If no diff, an empty string is // Diff return a diff of two objects. If no diff, an empty string is
// returned. // returned.
func Diff(a, b interface{}, options ...DiffOption) string { func Diff(a, b any, options ...DiffOption) string {
prettyC := prettyC prettyC := prettyC
prettyC.Formatter = defaultPrettyFormatters() prettyC.Formatter = defaultPrettyFormatters()
for _, option := range options { for _, option := range options {
@@ -84,6 +84,6 @@ var (
) )
// DiffFormatter adds a new formatter // DiffFormatter adds a new formatter
func DiffFormatter(t reflect.Type, fn interface{}) DiffOption { func DiffFormatter(t reflect.Type, fn any) DiffOption {
return DiffOption{kind: 3, t: t, fn: fn} return DiffOption{kind: 3, t: t, fn: fn}
} }

View File

@@ -24,12 +24,12 @@ type HTTPEndpointCases []struct {
Method string Method string
URL string URL string
Header http.Header Header http.Header
JSONInput interface{} JSONInput any
ContentType string ContentType string
StatusCode int StatusCode int
FirstLines []string FirstLines []string
JSONOutput interface{} JSONOutput any
} }
// TestHTTPEndpoints test a few HTTP endpoints // TestHTTPEndpoints test a few HTTP endpoints

View File

@@ -20,7 +20,7 @@ var Validate *validator.Validate
// register all subnetmaps. // register all subnetmaps.
func RegisterSubnetMapValidation[V any]() { func RegisterSubnetMapValidation[V any]() {
var zero SubnetMap[V] var zero SubnetMap[V]
validatorFunc := func(field reflect.Value) interface{} { validatorFunc := func(field reflect.Value) any {
switch subnetMap := field.Interface().(type) { switch subnetMap := field.Interface().(type) {
case SubnetMap[V]: case SubnetMap[V]:
return subnetMap.ToMap() return subnetMap.ToMap()
@@ -33,7 +33,7 @@ func RegisterSubnetMapValidation[V any]() {
} }
// netipValidation validates netip.Addr and netip.Prefix by turning them into a string. // netipValidation validates netip.Addr and netip.Prefix by turning them into a string.
func netipValidation(fl reflect.Value) interface{} { func netipValidation(fl reflect.Value) any {
switch netipSomething := fl.Interface().(type) { switch netipSomething := fl.Interface().(type) {
case netip.Addr: case netip.Addr:
if (netipSomething == netip.Addr{}) { if (netipSomething == netip.Addr{}) {

View File

@@ -93,7 +93,7 @@ func TestSubnetMapValidator(t *testing.T) {
cases := []struct { cases := []struct {
Description string Description string
Value interface{} Value any
Error bool Error bool
}{ }{
{ {
@@ -179,7 +179,7 @@ func TestNetIPValidation(t *testing.T) {
} }
cases := []struct { cases := []struct {
Description string Description string
Value interface{} Value any
Error bool Error bool
}{ }{
{ {

View File

@@ -8,6 +8,6 @@ import "gopkg.in/yaml.v3"
// Marshal serializes the value provided into a YAML document. The structure of // Marshal serializes the value provided into a YAML document. The structure of
// the generated document will reflect the structure of the value itself. Maps // the generated document will reflect the structure of the value itself. Maps
// and pointers (to struct, string, int, etc) are accepted as the in value. // and pointers (to struct, string, int, etc) are accepted as the in value.
func Marshal(in interface{}) (out []byte, err error) { func Marshal(in any) (out []byte, err error) {
return yaml.Marshal(in) return yaml.Marshal(in)
} }

View File

@@ -15,14 +15,14 @@ import (
// Unmarshal decodes the first document found within the in byte slice and // Unmarshal decodes the first document found within the in byte slice and
// assigns decoded values into the out value. // assigns decoded values into the out value.
func Unmarshal(in []byte, out interface{}) (err error) { func Unmarshal(in []byte, out any) (err error) {
return yaml.Unmarshal(in, out) return yaml.Unmarshal(in, out)
} }
// UnmarshalWithInclude decodes the first document found within the in byte // UnmarshalWithInclude decodes the first document found within the in byte
// slice and assigns decoded values into the out value. It also accepts the // slice and assigns decoded values into the out value. It also accepts the
// "!include" tag to include additional files contained in the provided fs. // "!include" tag to include additional files contained in the provided fs.
func UnmarshalWithInclude(fsys fs.FS, input string, out interface{}) (err error) { func UnmarshalWithInclude(fsys fs.FS, input string, out any) (err error) {
var outNode yaml.Node var outNode yaml.Node
in, err := fs.ReadFile(fsys, input) in, err := fs.ReadFile(fsys, input)
if err != nil { if err != nil {

View File

@@ -15,7 +15,7 @@ import (
func TestUnmarshalWithIn(t *testing.T) { func TestUnmarshalWithIn(t *testing.T) {
fsys := os.DirFS("testdata") fsys := os.DirFS("testdata")
var got interface{} var got any
if err := yaml.UnmarshalWithInclude(fsys, "base.yaml", &got); err != nil { if err := yaml.UnmarshalWithInclude(fsys, "base.yaml", &got); err != nil {
t.Fatalf("UnmarshalWithInclude() error:\n%+v", err) t.Fatalf("UnmarshalWithInclude() error:\n%+v", err)
} }
@@ -26,7 +26,7 @@ func TestUnmarshalWithIn(t *testing.T) {
"file1": gin.H{"name": "1.yaml"}, "file1": gin.H{"name": "1.yaml"},
}, },
"list1": []string{"el1", "el2", "el3"}, "list1": []string{"el1", "el2", "el3"},
"list2": []interface{}{gin.H{ "list2": []any{gin.H{
"protocol": "tcp", "protocol": "tcp",
"size": 1300, "size": 1300,
}, "el2", "el3"}, }, "el2", "el3"},

View File

@@ -61,6 +61,6 @@ type cacheLogger struct {
r *reporter.Reporter r *reporter.Reporter
} }
func (cl cacheLogger) Errorf(msg string, args ...interface{}) { func (cl cacheLogger) Errorf(msg string, args ...any) {
cl.r.Error().Msgf(msg, args...) cl.r.Error().Msgf(msg, args...)
} }

View File

@@ -104,7 +104,7 @@ func DefaultConfiguration() Configuration {
} }
// MarshalYAML undoes ConfigurationUnmarshallerHook(). // MarshalYAML undoes ConfigurationUnmarshallerHook().
func (cc CacheConfiguration) MarshalYAML() (interface{}, error) { func (cc CacheConfiguration) MarshalYAML() (any, error) {
return helpers.ParametrizedConfigurationMarshalYAML(cc, cacheConfigurationMap) return helpers.ParametrizedConfigurationMarshalYAML(cc, cacheConfigurationMap)
} }

View File

@@ -135,7 +135,7 @@ func NewConfig(r *reporter.Reporter, config Configuration) ([]kgo.Opt, error) {
// ConfigurationUnmarshallerHook normalize Kafka configuration: // ConfigurationUnmarshallerHook normalize Kafka configuration:
// - move SASL related parameters from TLS section to SASL section // - move SASL related parameters from TLS section to SASL section
func ConfigurationUnmarshallerHook() mapstructure.DecodeHookFunc { func ConfigurationUnmarshallerHook() mapstructure.DecodeHookFunc {
return func(from, to reflect.Value) (interface{}, error) { return func(from, to reflect.Value) (any, error) {
if from.Kind() != reflect.Map || from.IsNil() || !helpers.SameTypeOrSuperset(to.Type(), reflect.TypeOf(Configuration{})) { if from.Kind() != reflect.Map || from.IsNil() || !helpers.SameTypeOrSuperset(to.Type(), reflect.TypeOf(Configuration{})) {
return from.Interface(), nil return from.Interface(), nil
} }

View File

@@ -93,13 +93,13 @@ func TestTLSConfiguration(t *testing.T) {
helpers.TestConfigurationDecode(t, helpers.ConfigurationDecodeCases{ helpers.TestConfigurationDecode(t, helpers.ConfigurationDecodeCases{
{ {
Description: "no TLS", Description: "no TLS",
Initial: func() interface{} { return DefaultConfiguration() }, Initial: func() any { return DefaultConfiguration() },
Configuration: func() interface{} { return nil }, Configuration: func() any { return nil },
Expected: DefaultConfiguration(), Expected: DefaultConfiguration(),
}, { }, {
Description: "TLS without auth", Description: "TLS without auth",
Initial: func() interface{} { return DefaultConfiguration() }, Initial: func() any { return DefaultConfiguration() },
Configuration: func() interface{} { Configuration: func() any {
return gin.H{ return gin.H{
"tls": gin.H{ "tls": gin.H{
"enable": true, "enable": true,
@@ -116,8 +116,8 @@ func TestTLSConfiguration(t *testing.T) {
}, },
}, { }, {
Description: "TLS SASL plain, skip cert verification (old style)", Description: "TLS SASL plain, skip cert verification (old style)",
Initial: func() interface{} { return DefaultConfiguration() }, Initial: func() any { return DefaultConfiguration() },
Configuration: func() interface{} { Configuration: func() any {
return gin.H{ return gin.H{
"tls": gin.H{ "tls": gin.H{
"enable": true, "enable": true,
@@ -143,8 +143,8 @@ func TestTLSConfiguration(t *testing.T) {
}, },
}, { }, {
Description: "TLS SASL plain, skip cert verification", Description: "TLS SASL plain, skip cert verification",
Initial: func() interface{} { return DefaultConfiguration() }, Initial: func() any { return DefaultConfiguration() },
Configuration: func() interface{} { Configuration: func() any {
return gin.H{ return gin.H{
"sasl": gin.H{ "sasl": gin.H{
"username": "hello", "username": "hello",
@@ -168,8 +168,8 @@ func TestTLSConfiguration(t *testing.T) {
}, },
}, { }, {
Description: "TLS SASL SCRAM 256", Description: "TLS SASL SCRAM 256",
Initial: func() interface{} { return DefaultConfiguration() }, Initial: func() any { return DefaultConfiguration() },
Configuration: func() interface{} { Configuration: func() any {
return gin.H{ return gin.H{
"tls": gin.H{ "tls": gin.H{
"enable": true, "enable": true,
@@ -197,8 +197,8 @@ func TestTLSConfiguration(t *testing.T) {
}, },
}, { }, {
Description: "TLS SASL OAuth", Description: "TLS SASL OAuth",
Initial: func() interface{} { return DefaultConfiguration() }, Initial: func() any { return DefaultConfiguration() },
Configuration: func() interface{} { Configuration: func() any {
return gin.H{ return gin.H{
"tls": gin.H{ "tls": gin.H{
"enable": true, "enable": true,
@@ -230,8 +230,8 @@ func TestTLSConfiguration(t *testing.T) {
}, },
}, { }, {
Description: "OAuth requires a token URL", Description: "OAuth requires a token URL",
Initial: func() interface{} { return DefaultConfiguration() }, Initial: func() any { return DefaultConfiguration() },
Configuration: func() interface{} { Configuration: func() any {
return gin.H{ return gin.H{
"sasl": gin.H{ "sasl": gin.H{
"username": "hello", "username": "hello",
@@ -243,8 +243,8 @@ func TestTLSConfiguration(t *testing.T) {
Error: true, Error: true,
}, { }, {
Description: "OAuth token URL only with OAuth", Description: "OAuth token URL only with OAuth",
Initial: func() interface{} { return DefaultConfiguration() }, Initial: func() any { return DefaultConfiguration() },
Configuration: func() interface{} { Configuration: func() any {
return gin.H{ return gin.H{
"sasl": gin.H{ "sasl": gin.H{
"username": "hello", "username": "hello",

View File

@@ -18,8 +18,8 @@ func TestSourceDecode(t *testing.T) {
helpers.TestConfigurationDecode(t, helpers.ConfigurationDecodeCases{ helpers.TestConfigurationDecode(t, helpers.ConfigurationDecodeCases{
{ {
Description: "Empty", Description: "Empty",
Initial: func() interface{} { return Source{} }, Initial: func() any { return Source{} },
Configuration: func() interface{} { Configuration: func() any {
return gin.H{ return gin.H{
"url": "https://example.net", "url": "https://example.net",
"interval": "10m", "interval": "10m",
@@ -33,8 +33,8 @@ func TestSourceDecode(t *testing.T) {
}, },
}, { }, {
Description: "Simple transform", Description: "Simple transform",
Initial: func() interface{} { return Source{} }, Initial: func() any { return Source{} },
Configuration: func() interface{} { Configuration: func() any {
return gin.H{ return gin.H{
"url": "https://example.net", "url": "https://example.net",
"interval": "10m", "interval": "10m",
@@ -50,8 +50,8 @@ func TestSourceDecode(t *testing.T) {
}, },
}, { }, {
Description: "Use POST", Description: "Use POST",
Initial: func() interface{} { return Source{} }, Initial: func() any { return Source{} },
Configuration: func() interface{} { Configuration: func() any {
return gin.H{ return gin.H{
"url": "https://example.net", "url": "https://example.net",
"method": "POST", "method": "POST",
@@ -69,8 +69,8 @@ func TestSourceDecode(t *testing.T) {
}, },
}, { }, {
Description: "Complex transform", Description: "Complex transform",
Initial: func() interface{} { return Source{} }, Initial: func() any { return Source{} },
Configuration: func() interface{} { Configuration: func() any {
return gin.H{ return gin.H{
"url": "https://example.net", "url": "https://example.net",
"interval": "10m", "interval": "10m",
@@ -90,8 +90,8 @@ func TestSourceDecode(t *testing.T) {
}, },
}, { }, {
Description: "Incorrect transform", Description: "Incorrect transform",
Initial: func() interface{} { return Source{} }, Initial: func() any { return Source{} },
Configuration: func() interface{} { Configuration: func() any {
return gin.H{ return gin.H{
"url": "https://example.net", "url": "https://example.net",
"interval": "10m", "interval": "10m",

View File

@@ -28,7 +28,7 @@ import (
type ProviderFunc func(ctx context.Context, name string, source Source) (int, error) type ProviderFunc func(ctx context.Context, name string, source Source) (int, error)
// Component represents a remote data source fetcher. // Component represents a remote data source fetcher.
type Component[T interface{}] struct { type Component[T any] struct {
r *reporter.Reporter r *reporter.Reporter
t tomb.Tomb t tomb.Tomb
provider ProviderFunc provider ProviderFunc
@@ -40,7 +40,7 @@ type Component[T interface{}] struct {
} }
// New creates a new remote data source fetcher component. // New creates a new remote data source fetcher component.
func New[T interface{}](r *reporter.Reporter, provider ProviderFunc, dataType string, dataSources map[string]Source) (*Component[T], error) { func New[T any](r *reporter.Reporter, provider ProviderFunc, dataType string, dataSources map[string]Source) (*Component[T], error) {
c := Component[T]{ c := Component[T]{
r: r, r: r,
provider: provider, provider: provider,
@@ -104,7 +104,7 @@ func (c *Component[T]) Fetch(ctx context.Context, name string, source Source) ([
} }
reader := bufio.NewReader(resp.Body) reader := bufio.NewReader(resp.Body)
decoder := json.NewDecoder(reader) decoder := json.NewDecoder(reader)
var got interface{} var got any
if err := decoder.Decode(&got); err != nil { if err := decoder.Decode(&got); err != nil {
l.Err(err).Msg("cannot decode JSON output") l.Err(err).Msg("cannot decode JSON output")
return nil, ErrJSONDecode return nil, ErrJSONDecode

View File

@@ -15,7 +15,7 @@ type promHTTPLogger struct {
} }
// Println outputs // Println outputs
func (m promHTTPLogger) Println(v ...interface{}) { func (m promHTTPLogger) Println(v ...any) {
if e := m.l.Debug(); e.Enabled() { if e := m.l.Debug(); e.Enabled() {
e.Msg(fmt.Sprint(v...)) e.Msg(fmt.Sprint(v...))
} }

View File

@@ -21,7 +21,7 @@ type Call uintptr
type Trace []Call type Trace []Call
var pcStackPool = sync.Pool{ var pcStackPool = sync.Pool{
New: func() interface{} { return make([]uintptr, 1000) }, New: func() any { return make([]uintptr, 1000) },
} }
func poolBuf() []uintptr { func poolBuf() []uintptr {

View File

@@ -47,7 +47,7 @@ func (customHeaderBinding) Name() string {
} }
// Bind will bind struct fields to HTTP headers using the configured mapping. // Bind will bind struct fields to HTTP headers using the configured mapping.
func (b customHeaderBinding) Bind(req *http.Request, obj interface{}) error { func (b customHeaderBinding) Bind(req *http.Request, obj any) error {
value := reflect.ValueOf(obj).Elem() value := reflect.ValueOf(obj).Elem()
tValue := reflect.TypeOf(obj).Elem() tValue := reflect.TypeOf(obj).Elem()
if value.Kind() != reflect.Struct { if value.Kind() != reflect.Struct {

View File

@@ -22,15 +22,15 @@ func (l *logger) LogMode(gormlogger.LogLevel) gormlogger.Interface {
return l return l
} }
func (l *logger) Info(_ context.Context, s string, args ...interface{}) { func (l *logger) Info(_ context.Context, s string, args ...any) {
l.r.Info().Msgf(s, args...) l.r.Info().Msgf(s, args...)
} }
func (l *logger) Warn(_ context.Context, s string, args ...interface{}) { func (l *logger) Warn(_ context.Context, s string, args ...any) {
l.r.Warn().Msgf(s, args...) l.r.Warn().Msgf(s, args...)
} }
func (l *logger) Error(_ context.Context, s string, args ...interface{}) { func (l *logger) Error(_ context.Context, s string, args ...any) {
l.r.Error().Msgf(s, args...) l.r.Error().Msgf(s, args...)
} }

View File

@@ -188,18 +188,18 @@ func lastIP(subnet netip.Prefix) netip.Addr {
return netip.AddrFrom16(a16) return netip.AddrFrom16(a16)
} }
func quote(v interface{}) string { func quote(v any) string {
return "'" + strings.NewReplacer(`\`, `\\`, `'`, `\'`).Replace(toString(v)) + "'" return "'" + strings.NewReplacer(`\`, `\\`, `'`, `\'`).Replace(toString(v)) + "'"
} }
func toSlice(v interface{}) []interface{} { func toSlice(v any) []any {
if v == nil { if v == nil {
return nil return nil
} }
return v.([]interface{}) return v.([]any)
} }
func toString(v interface{}) string { func toString(v any) string {
switch s := v.(type) { switch s := v.(type) {
case string: case string:
return s return s

View File

@@ -64,7 +64,7 @@ LIMIT 1`, strings.Join(selectClause, ",\n "))
var ( var (
response = gin.H{} response = gin.H{}
columnTypes = rows.ColumnTypes() columnTypes = rows.ColumnTypes()
vars = make([]interface{}, len(columnTypes)) vars = make([]any, len(columnTypes))
) )
for i := range columnTypes { for i := range columnTypes {
vars[i] = reflect.New(columnTypes[i].ScanType()).Interface() vars[i] = reflect.New(columnTypes[i].ScanType()).Interface()

View File

@@ -67,7 +67,7 @@ LIMIT 1`).
}).AnyTimes() }).AnyTimes()
mockRows.EXPECT().Scan(gomock.Any()). mockRows.EXPECT().Scan(gomock.Any()).
DoAndReturn(func(args ...interface{}) interface{} { DoAndReturn(func(args ...any) any {
arg0 := args[0].(*time.Time) arg0 := args[0].(*time.Time)
*arg0 = time.Date(2022, 4, 4, 8, 36, 11, 10, time.UTC) *arg0 = time.Date(2022, 4, 4, 8, 36, 11, 10, time.UTC)
arg1 := args[1].(*uint64) arg1 := args[1].(*uint64)

View File

@@ -17,7 +17,7 @@ func (c *Component) newOID(oid string, t gosnmp.Asn1BER, onGet GoSNMPServer.Func
return &GoSNMPServer.PDUValueControlItem{ return &GoSNMPServer.PDUValueControlItem{
OID: oid, OID: oid,
Type: t, Type: t,
OnGet: func() (interface{}, error) { OnGet: func() (any, error) {
c.metrics.requests.WithLabelValues(oid).Inc() c.metrics.requests.WithLabelValues(oid).Inc()
return onGet() return onGet()
}, },
@@ -28,7 +28,7 @@ func (c *Component) startSNMPServer() error {
oids := make([]*GoSNMPServer.PDUValueControlItem, 1+4*len(c.config.Interfaces)) oids := make([]*GoSNMPServer.PDUValueControlItem, 1+4*len(c.config.Interfaces))
oids[0] = c.newOID("1.3.6.1.2.1.1.5.0", oids[0] = c.newOID("1.3.6.1.2.1.1.5.0",
gosnmp.OctetString, gosnmp.OctetString,
func() (interface{}, error) { func() (any, error) {
return c.config.Name, nil return c.config.Name, nil
}, },
) )
@@ -38,25 +38,25 @@ func (c *Component) startSNMPServer() error {
d := description d := description
oids[4*count+1] = c.newOID(fmt.Sprintf("1.3.6.1.2.1.2.2.1.2.%d", i), oids[4*count+1] = c.newOID(fmt.Sprintf("1.3.6.1.2.1.2.2.1.2.%d", i),
gosnmp.OctetString, gosnmp.OctetString,
func() (interface{}, error) { func() (any, error) {
return fmt.Sprintf("Gi0/0/0/%d", i), nil return fmt.Sprintf("Gi0/0/0/%d", i), nil
}, },
) )
oids[4*count+2] = c.newOID(fmt.Sprintf("1.3.6.1.2.1.31.1.1.1.1.%d", i), oids[4*count+2] = c.newOID(fmt.Sprintf("1.3.6.1.2.1.31.1.1.1.1.%d", i),
gosnmp.OctetString, gosnmp.OctetString,
func() (interface{}, error) { func() (any, error) {
return fmt.Sprintf("Gi0/0/0/%d", i), nil return fmt.Sprintf("Gi0/0/0/%d", i), nil
}, },
) )
oids[4*count+3] = c.newOID(fmt.Sprintf("1.3.6.1.2.1.31.1.1.1.15.%d", i), oids[4*count+3] = c.newOID(fmt.Sprintf("1.3.6.1.2.1.31.1.1.1.15.%d", i),
gosnmp.Gauge32, gosnmp.Gauge32,
func() (interface{}, error) { func() (any, error) {
return uint(10000), nil return uint(10000), nil
}, },
) )
oids[4*count+4] = c.newOID(fmt.Sprintf("1.3.6.1.2.1.31.1.1.1.18.%d", i), oids[4*count+4] = c.newOID(fmt.Sprintf("1.3.6.1.2.1.31.1.1.1.18.%d", i),
gosnmp.OctetString, gosnmp.OctetString,
func() (interface{}, error) { func() (any, error) {
return d, nil return d, nil
}, },
) )

View File

@@ -46,7 +46,7 @@ type InputConfiguration struct {
} }
// MarshalYAML undoes ConfigurationUnmarshallerHook(). // MarshalYAML undoes ConfigurationUnmarshallerHook().
func (ic InputConfiguration) MarshalYAML() (interface{}, error) { func (ic InputConfiguration) MarshalYAML() (any, error) {
return helpers.ParametrizedConfigurationMarshalYAML(ic, inputs) return helpers.ParametrizedConfigurationMarshalYAML(ic, inputs)
} }

View File

@@ -21,8 +21,8 @@ func TestDecodeConfiguration(t *testing.T) {
helpers.TestConfigurationDecode(t, helpers.ConfigurationDecodeCases{ helpers.TestConfigurationDecode(t, helpers.ConfigurationDecodeCases{
{ {
Description: "from empty configuration", Description: "from empty configuration",
Initial: func() interface{} { return Configuration{} }, Initial: func() any { return Configuration{} },
Configuration: func() interface{} { Configuration: func() any {
return gin.H{ return gin.H{
"inputs": []gin.H{ "inputs": []gin.H{
{ {
@@ -61,7 +61,7 @@ func TestDecodeConfiguration(t *testing.T) {
}, },
}, { }, {
Description: "from existing configuration", Description: "from existing configuration",
Initial: func() interface{} { Initial: func() any {
return Configuration{ return Configuration{
Inputs: []InputConfiguration{{ Inputs: []InputConfiguration{{
Decoder: pb.RawFlow_DECODER_NETFLOW, Decoder: pb.RawFlow_DECODER_NETFLOW,
@@ -72,7 +72,7 @@ func TestDecodeConfiguration(t *testing.T) {
}}, }},
} }
}, },
Configuration: func() interface{} { Configuration: func() any {
return gin.H{ return gin.H{
"inputs": []gin.H{ "inputs": []gin.H{
{ {
@@ -108,7 +108,7 @@ func TestDecodeConfiguration(t *testing.T) {
}, },
}, { }, {
Description: "change type", Description: "change type",
Initial: func() interface{} { Initial: func() any {
return Configuration{ return Configuration{
Inputs: []InputConfiguration{{ Inputs: []InputConfiguration{{
Decoder: pb.RawFlow_DECODER_NETFLOW, Decoder: pb.RawFlow_DECODER_NETFLOW,
@@ -116,7 +116,7 @@ func TestDecodeConfiguration(t *testing.T) {
}}, }},
} }
}, },
Configuration: func() interface{} { Configuration: func() any {
return gin.H{ return gin.H{
"inputs": []gin.H{ "inputs": []gin.H{
{ {
@@ -136,7 +136,7 @@ func TestDecodeConfiguration(t *testing.T) {
}, },
}, { }, {
Description: "only set one item", Description: "only set one item",
Initial: func() interface{} { Initial: func() any {
return Configuration{ return Configuration{
Inputs: []InputConfiguration{{ Inputs: []InputConfiguration{{
Decoder: pb.RawFlow_DECODER_NETFLOW, Decoder: pb.RawFlow_DECODER_NETFLOW,
@@ -149,7 +149,7 @@ func TestDecodeConfiguration(t *testing.T) {
}}, }},
} }
}, },
Configuration: func() interface{} { Configuration: func() any {
return gin.H{ return gin.H{
"inputs": []gin.H{ "inputs": []gin.H{
{ {
@@ -170,10 +170,10 @@ func TestDecodeConfiguration(t *testing.T) {
}, },
}, { }, {
Description: "incorrect decoder", Description: "incorrect decoder",
Initial: func() interface{} { Initial: func() any {
return Configuration{} return Configuration{}
}, },
Configuration: func() interface{} { Configuration: func() any {
return gin.H{ return gin.H{
"inputs": []gin.H{ "inputs": []gin.H{
{ {
@@ -194,7 +194,7 @@ func TestDecodeConfiguration(t *testing.T) {
}, },
{ {
Description: "netflow timestamp source netflow-packet", Description: "netflow timestamp source netflow-packet",
Initial: func() interface{} { Initial: func() any {
return Configuration{ return Configuration{
Inputs: []InputConfiguration{{ Inputs: []InputConfiguration{{
Decoder: pb.RawFlow_DECODER_NETFLOW, Decoder: pb.RawFlow_DECODER_NETFLOW,
@@ -206,7 +206,7 @@ func TestDecodeConfiguration(t *testing.T) {
}}, }},
} }
}, },
Configuration: func() interface{} { Configuration: func() any {
return gin.H{ return gin.H{
"inputs": []gin.H{ "inputs": []gin.H{
{ {
@@ -230,7 +230,7 @@ func TestDecodeConfiguration(t *testing.T) {
}, },
{ {
Description: "netflow timestamp source netflow-first-switched", Description: "netflow timestamp source netflow-first-switched",
Initial: func() interface{} { Initial: func() any {
return Configuration{ return Configuration{
Inputs: []InputConfiguration{{ Inputs: []InputConfiguration{{
Decoder: pb.RawFlow_DECODER_NETFLOW, Decoder: pb.RawFlow_DECODER_NETFLOW,
@@ -242,7 +242,7 @@ func TestDecodeConfiguration(t *testing.T) {
}}, }},
} }
}, },
Configuration: func() interface{} { Configuration: func() any {
return gin.H{ return gin.H{
"inputs": []gin.H{ "inputs": []gin.H{
{ {

View File

@@ -105,7 +105,7 @@ type NetworkAttributes struct {
// also accepts a string instead of attributes for backward // also accepts a string instead of attributes for backward
// compatibility. // compatibility.
func NetworkAttributesUnmarshallerHook() mapstructure.DecodeHookFunc { func NetworkAttributesUnmarshallerHook() mapstructure.DecodeHookFunc {
return func(from, to reflect.Value) (interface{}, error) { return func(from, to reflect.Value) (any, error) {
from = helpers.ElemOrIdentity(from) from = helpers.ElemOrIdentity(from)
to = helpers.ElemOrIdentity(to) to = helpers.ElemOrIdentity(to)
if to.Type() != reflect.TypeOf(NetworkAttributes{}) { if to.Type() != reflect.TypeOf(NetworkAttributes{}) {

View File

@@ -17,46 +17,46 @@ func TestNetworkNamesUnmarshalHook(t *testing.T) {
helpers.TestConfigurationDecode(t, helpers.ConfigurationDecodeCases{ helpers.TestConfigurationDecode(t, helpers.ConfigurationDecodeCases{
{ {
Description: "nil", Description: "nil",
Initial: func() interface{} { return helpers.SubnetMap[NetworkAttributes]{} }, Initial: func() any { return helpers.SubnetMap[NetworkAttributes]{} },
Configuration: func() interface{} { return nil }, Configuration: func() any { return nil },
Expected: helpers.SubnetMap[NetworkAttributes]{}, Expected: helpers.SubnetMap[NetworkAttributes]{},
}, { }, {
Description: "empty", Description: "empty",
Initial: func() interface{} { return helpers.SubnetMap[NetworkAttributes]{} }, Initial: func() any { return helpers.SubnetMap[NetworkAttributes]{} },
Configuration: func() interface{} { return gin.H{} }, Configuration: func() any { return gin.H{} },
Expected: helpers.SubnetMap[NetworkAttributes]{}, Expected: helpers.SubnetMap[NetworkAttributes]{},
}, { }, {
Description: "IPv4", Description: "IPv4",
Initial: func() interface{} { return helpers.SubnetMap[NetworkAttributes]{} }, Initial: func() any { return helpers.SubnetMap[NetworkAttributes]{} },
Configuration: func() interface{} { return gin.H{"203.0.113.0/24": gin.H{"name": "customer"}} }, Configuration: func() any { return gin.H{"203.0.113.0/24": gin.H{"name": "customer"}} },
Expected: helpers.MustNewSubnetMap(map[string]NetworkAttributes{ Expected: helpers.MustNewSubnetMap(map[string]NetworkAttributes{
"::ffff:203.0.113.0/120": {Name: "customer"}, "::ffff:203.0.113.0/120": {Name: "customer"},
}), }),
}, { }, {
Description: "IPv6", Description: "IPv6",
Initial: func() interface{} { return helpers.SubnetMap[NetworkAttributes]{} }, Initial: func() any { return helpers.SubnetMap[NetworkAttributes]{} },
Configuration: func() interface{} { return gin.H{"2001:db8:1::/64": gin.H{"name": "customer"}} }, Configuration: func() any { return gin.H{"2001:db8:1::/64": gin.H{"name": "customer"}} },
Expected: helpers.MustNewSubnetMap(map[string]NetworkAttributes{ Expected: helpers.MustNewSubnetMap(map[string]NetworkAttributes{
"2001:db8:1::/64": {Name: "customer"}, "2001:db8:1::/64": {Name: "customer"},
}), }),
}, { }, {
Description: "IPv4 subnet (compatibility)", Description: "IPv4 subnet (compatibility)",
Initial: func() interface{} { return helpers.SubnetMap[NetworkAttributes]{} }, Initial: func() any { return helpers.SubnetMap[NetworkAttributes]{} },
Configuration: func() interface{} { return gin.H{"203.0.113.0/24": "customer"} }, Configuration: func() any { return gin.H{"203.0.113.0/24": "customer"} },
Expected: helpers.MustNewSubnetMap(map[string]NetworkAttributes{ Expected: helpers.MustNewSubnetMap(map[string]NetworkAttributes{
"::ffff:203.0.113.0/120": {Name: "customer"}, "::ffff:203.0.113.0/120": {Name: "customer"},
}), }),
}, { }, {
Description: "IPv6 subnet (compatibility)", Description: "IPv6 subnet (compatibility)",
Initial: func() interface{} { return helpers.SubnetMap[NetworkAttributes]{} }, Initial: func() any { return helpers.SubnetMap[NetworkAttributes]{} },
Configuration: func() interface{} { return gin.H{"2001:db8:1::/64": "customer"} }, Configuration: func() any { return gin.H{"2001:db8:1::/64": "customer"} },
Expected: helpers.MustNewSubnetMap(map[string]NetworkAttributes{ Expected: helpers.MustNewSubnetMap(map[string]NetworkAttributes{
"2001:db8:1::/64": {Name: "customer"}, "2001:db8:1::/64": {Name: "customer"},
}), }),
}, { }, {
Description: "all attributes", Description: "all attributes",
Initial: func() interface{} { return helpers.SubnetMap[NetworkAttributes]{} }, Initial: func() any { return helpers.SubnetMap[NetworkAttributes]{} },
Configuration: func() interface{} { Configuration: func() any {
return gin.H{"203.0.113.0/24": gin.H{ return gin.H{"203.0.113.0/24": gin.H{
"name": "customer1", "name": "customer1",
"role": "customer", "role": "customer",
@@ -74,13 +74,13 @@ func TestNetworkNamesUnmarshalHook(t *testing.T) {
}}), }}),
}, { }, {
Description: "Invalid subnet (1)", Description: "Invalid subnet (1)",
Initial: func() interface{} { return helpers.SubnetMap[NetworkAttributes]{} }, Initial: func() any { return helpers.SubnetMap[NetworkAttributes]{} },
Configuration: func() interface{} { return gin.H{"192.0.2.1/38": "customer"} }, Configuration: func() any { return gin.H{"192.0.2.1/38": "customer"} },
Error: true, Error: true,
}, { }, {
Description: "Invalid subnet (2)", Description: "Invalid subnet (2)",
Initial: func() interface{} { return helpers.SubnetMap[NetworkAttributes]{} }, Initial: func() any { return helpers.SubnetMap[NetworkAttributes]{} },
Configuration: func() interface{} { return gin.H{"192.0.2.1/255.0.255.0": "customer"} }, Configuration: func() any { return gin.H{"192.0.2.1/255.0.255.0": "customer"} },
Error: true, Error: true,
}, },
}, helpers.DiffFormatter(reflect.TypeOf(helpers.SubnetMap[NetworkAttributes]{}), fmt.Sprint)) }, helpers.DiffFormatter(reflect.TypeOf(helpers.SubnetMap[NetworkAttributes]{}), fmt.Sprint))

View File

@@ -19,7 +19,7 @@ type migrationStep struct {
// CheckQuery to execute to check if the step is needed. // CheckQuery to execute to check if the step is needed.
CheckQuery string CheckQuery string
// Arguments to use for the query // Arguments to use for the query
Args []interface{} Args []any
// Function to execute if the query returns no row or returns `0'. // Function to execute if the query returns no row or returns `0'.
Do func() error Do func() error
} }

View File

@@ -15,18 +15,18 @@ func TestConfigurationUnmarshallerHook(t *testing.T) {
helpers.TestConfigurationDecode(t, helpers.ConfigurationDecodeCases{ helpers.TestConfigurationDecode(t, helpers.ConfigurationDecodeCases{
{ {
Description: "nil", Description: "nil",
Initial: func() interface{} { return Configuration{} }, Initial: func() any { return Configuration{} },
Configuration: func() interface{} { return nil }, Configuration: func() any { return nil },
Expected: Configuration{}, Expected: Configuration{},
}, { }, {
Description: "empty", Description: "empty",
Initial: func() interface{} { return Configuration{} }, Initial: func() any { return Configuration{} },
Configuration: func() interface{} { return gin.H{} }, Configuration: func() any { return gin.H{} },
Expected: Configuration{}, Expected: Configuration{},
}, { }, {
Description: "no country-database, no geoip-database", Description: "no country-database, no geoip-database",
Initial: func() interface{} { return Configuration{} }, Initial: func() any { return Configuration{} },
Configuration: func() interface{} { Configuration: func() any {
return gin.H{ return gin.H{
"asn-database": []string{"something"}, "asn-database": []string{"something"},
"optional": true, "optional": true,
@@ -38,8 +38,8 @@ func TestConfigurationUnmarshallerHook(t *testing.T) {
}, },
}, { }, {
Description: "country-database, no geoip-database", Description: "country-database, no geoip-database",
Initial: func() interface{} { return Configuration{} }, Initial: func() any { return Configuration{} },
Configuration: func() interface{} { Configuration: func() any {
return gin.H{ return gin.H{
"asn-database": []string{"something"}, "asn-database": []string{"something"},
"country-database": []string{"something else"}, "country-database": []string{"something else"},
@@ -51,8 +51,8 @@ func TestConfigurationUnmarshallerHook(t *testing.T) {
}, },
}, { }, {
Description: "no country-database, geoip-database", Description: "no country-database, geoip-database",
Initial: func() interface{} { return Configuration{} }, Initial: func() any { return Configuration{} },
Configuration: func() interface{} { Configuration: func() any {
return gin.H{ return gin.H{
"asn-database": []string{"something"}, "asn-database": []string{"something"},
"geo-database": []string{"something else"}, "geo-database": []string{"something else"},
@@ -64,8 +64,8 @@ func TestConfigurationUnmarshallerHook(t *testing.T) {
}, },
}, { }, {
Description: "both country-database, geoip-database", Description: "both country-database, geoip-database",
Initial: func() interface{} { return Configuration{} }, Initial: func() any { return Configuration{} },
Configuration: func() interface{} { Configuration: func() any {
return gin.H{ return gin.H{
"asn-database": []string{"something"}, "asn-database": []string{"something"},
"geo-database": []string{"something else"}, "geo-database": []string{"something else"},

View File

@@ -20,7 +20,7 @@ func (c *Component) configurationHandlerFunc(gc *gin.Context) {
} }
c.serviceLock.Lock() c.serviceLock.Lock()
var configuration interface{} var configuration any
serviceConfigurations, ok := c.serviceConfigurations[ServiceType(service)] serviceConfigurations, ok := c.serviceConfigurations[ServiceType(service)]
if ok { if ok {
l := len(serviceConfigurations) l := len(serviceConfigurations)

View File

@@ -18,7 +18,7 @@ type Component struct {
config Configuration config Configuration
serviceLock sync.Mutex serviceLock sync.Mutex
serviceConfigurations map[ServiceType][]interface{} serviceConfigurations map[ServiceType][]any
} }
// Dependencies define the dependencies of the broker. // Dependencies define the dependencies of the broker.
@@ -49,7 +49,7 @@ func New(r *reporter.Reporter, configuration Configuration, dependencies Depende
d: &dependencies, d: &dependencies,
config: configuration, config: configuration,
serviceConfigurations: map[ServiceType][]interface{}{}, serviceConfigurations: map[ServiceType][]any{},
} }
c.d.HTTP.GinRouter.GET("/api/v0/orchestrator/configuration/:service", c.configurationHandlerFunc) c.d.HTTP.GinRouter.GET("/api/v0/orchestrator/configuration/:service", c.configurationHandlerFunc)
@@ -59,10 +59,10 @@ func New(r *reporter.Reporter, configuration Configuration, dependencies Depende
} }
// RegisterConfiguration registers the configuration for a service. // RegisterConfiguration registers the configuration for a service.
func (c *Component) RegisterConfiguration(service ServiceType, configuration interface{}) { func (c *Component) RegisterConfiguration(service ServiceType, configuration any) {
c.serviceLock.Lock() c.serviceLock.Lock()
if _, ok := c.serviceConfigurations[service]; !ok { if _, ok := c.serviceConfigurations[service]; !ok {
c.serviceConfigurations[service] = []interface{}{} c.serviceConfigurations[service] = []any{}
} }
c.serviceConfigurations[service] = append(c.serviceConfigurations[service], configuration) c.serviceConfigurations[service] = append(c.serviceConfigurations[service], configuration)
c.serviceLock.Unlock() c.serviceLock.Unlock()

View File

@@ -75,7 +75,7 @@ const (
// ASNProviderUnmarshallerHook normalize a net provider configuration: // ASNProviderUnmarshallerHook normalize a net provider configuration:
// - map bmp to routing // - map bmp to routing
func ASNProviderUnmarshallerHook() mapstructure.DecodeHookFunc { func ASNProviderUnmarshallerHook() mapstructure.DecodeHookFunc {
return func(from, to reflect.Value) (interface{}, error) { return func(from, to reflect.Value) (any, error) {
if from.Kind() != reflect.String || to.Type() != reflect.TypeOf(ASNProvider(0)) { if from.Kind() != reflect.String || to.Type() != reflect.TypeOf(ASNProvider(0)) {
return from.Interface(), nil return from.Interface(), nil
} }
@@ -92,7 +92,7 @@ func ASNProviderUnmarshallerHook() mapstructure.DecodeHookFunc {
// NetProviderUnmarshallerHook normalize a net provider configuration: // NetProviderUnmarshallerHook normalize a net provider configuration:
// - map bmp to routing // - map bmp to routing
func NetProviderUnmarshallerHook() mapstructure.DecodeHookFunc { func NetProviderUnmarshallerHook() mapstructure.DecodeHookFunc {
return func(from, to reflect.Value) (interface{}, error) { return func(from, to reflect.Value) (any, error) {
if from.Kind() != reflect.String || to.Type() != reflect.TypeOf(NetProvider(0)) { if from.Kind() != reflect.String || to.Type() != reflect.TypeOf(NetProvider(0)) {
return from.Interface(), nil return from.Interface(), nil
} }
@@ -106,7 +106,7 @@ func NetProviderUnmarshallerHook() mapstructure.DecodeHookFunc {
// ConfigurationUnmarshallerHook normalize core configuration: // ConfigurationUnmarshallerHook normalize core configuration:
// - replace ignore-asn-from-flow by asn-providers // - replace ignore-asn-from-flow by asn-providers
func ConfigurationUnmarshallerHook() mapstructure.DecodeHookFunc { func ConfigurationUnmarshallerHook() mapstructure.DecodeHookFunc {
return func(from, to reflect.Value) (interface{}, error) { return func(from, to reflect.Value) (any, error) {
if from.Kind() != reflect.Map || from.IsNil() || to.Type() != reflect.TypeOf(Configuration{}) { if from.Kind() != reflect.Map || from.IsNil() || to.Type() != reflect.TypeOf(Configuration{}) {
return from.Interface(), nil return from.Interface(), nil
} }

View File

@@ -21,20 +21,20 @@ func TestConfigurationUnmarshallerHook(t *testing.T) {
helpers.TestConfigurationDecode(t, helpers.ConfigurationDecodeCases{ helpers.TestConfigurationDecode(t, helpers.ConfigurationDecodeCases{
{ {
Description: "nil", Description: "nil",
Initial: func() interface{} { return Configuration{} }, Initial: func() any { return Configuration{} },
Configuration: func() interface{} { return nil }, Configuration: func() any { return nil },
Expected: Configuration{}, Expected: Configuration{},
SkipValidation: true, SkipValidation: true,
}, { }, {
Description: "empty", Description: "empty",
Initial: func() interface{} { return Configuration{} }, Initial: func() any { return Configuration{} },
Configuration: func() interface{} { return gin.H{} }, Configuration: func() any { return gin.H{} },
Expected: Configuration{}, Expected: Configuration{},
SkipValidation: true, SkipValidation: true,
}, { }, {
Description: "ignore-asn-from-flow = false", Description: "ignore-asn-from-flow = false",
Initial: func() interface{} { return Configuration{} }, Initial: func() any { return Configuration{} },
Configuration: func() interface{} { Configuration: func() any {
return gin.H{ return gin.H{
"ignore-asn-from-flow": false, "ignore-asn-from-flow": false,
} }
@@ -43,8 +43,8 @@ func TestConfigurationUnmarshallerHook(t *testing.T) {
SkipValidation: true, SkipValidation: true,
}, { }, {
Description: "ignore-asn-from-flow = true", Description: "ignore-asn-from-flow = true",
Initial: func() interface{} { return Configuration{} }, Initial: func() any { return Configuration{} },
Configuration: func() interface{} { Configuration: func() any {
return gin.H{ return gin.H{
"ignore-asn-from-flow": true, "ignore-asn-from-flow": true,
} }
@@ -55,8 +55,8 @@ func TestConfigurationUnmarshallerHook(t *testing.T) {
SkipValidation: true, SkipValidation: true,
}, { }, {
Description: "ignore-asn-from-flow and asn-providers", Description: "ignore-asn-from-flow and asn-providers",
Initial: func() interface{} { return Configuration{} }, Initial: func() any { return Configuration{} },
Configuration: func() interface{} { Configuration: func() any {
return gin.H{ return gin.H{
"ignore-asn-from-flow": true, "ignore-asn-from-flow": true,
"asn-providers": []string{"routing", "flow"}, "asn-providers": []string{"routing", "flow"},
@@ -66,8 +66,8 @@ func TestConfigurationUnmarshallerHook(t *testing.T) {
SkipValidation: true, SkipValidation: true,
}, { }, {
Description: "asn-providers only", Description: "asn-providers only",
Initial: func() interface{} { return Configuration{} }, Initial: func() any { return Configuration{} },
Configuration: func() interface{} { Configuration: func() any {
return gin.H{ return gin.H{
"asn-providers": []string{"flow-except-private", "routing", "flow"}, "asn-providers": []string{"flow-except-private", "routing", "flow"},
} }
@@ -78,8 +78,8 @@ func TestConfigurationUnmarshallerHook(t *testing.T) {
SkipValidation: true, SkipValidation: true,
}, { }, {
Description: "net-providers with bmp", Description: "net-providers with bmp",
Initial: func() interface{} { return Configuration{} }, Initial: func() any { return Configuration{} },
Configuration: func() interface{} { Configuration: func() any {
return gin.H{ return gin.H{
"net-providers": []string{"flow", "bmp"}, "net-providers": []string{"flow", "bmp"},
} }
@@ -90,8 +90,8 @@ func TestConfigurationUnmarshallerHook(t *testing.T) {
SkipValidation: true, SkipValidation: true,
}, { }, {
Description: "asn-providers with bmp", Description: "asn-providers with bmp",
Initial: func() interface{} { return Configuration{} }, Initial: func() any { return Configuration{} },
Configuration: func() interface{} { Configuration: func() any {
return gin.H{ return gin.H{
"asn-providers": []string{"flow", "bmp", "bmp-except-private"}, "asn-providers": []string{"flow", "bmp", "bmp-except-private"},
} }
@@ -102,8 +102,8 @@ func TestConfigurationUnmarshallerHook(t *testing.T) {
SkipValidation: true, SkipValidation: true,
}, { }, {
Description: "net-providers", Description: "net-providers",
Initial: func() interface{} { return Configuration{} }, Initial: func() any { return Configuration{} },
Configuration: func() interface{} { Configuration: func() any {
return gin.H{ return gin.H{
"net-providers": []string{"flow", "routing"}, "net-providers": []string{"flow", "routing"},
} }

View File

@@ -52,7 +52,7 @@ func TestEnrich(t *testing.T) {
InIf: 100, InIf: 100,
OutIf: 200, OutIf: 200,
ExporterAddress: netip.MustParseAddr("::ffff:192.0.2.142"), ExporterAddress: netip.MustParseAddr("::ffff:192.0.2.142"),
OtherColumns: map[schema.ColumnKey]interface{}{ OtherColumns: map[schema.ColumnKey]any{
schema.ColumnExporterName: "192_0_2_142", schema.ColumnExporterName: "192_0_2_142",
schema.ColumnInIfName: "Gi0/0/100", schema.ColumnInIfName: "Gi0/0/100",
schema.ColumnOutIfName: "Gi0/0/200", schema.ColumnOutIfName: "Gi0/0/200",
@@ -82,7 +82,7 @@ func TestEnrich(t *testing.T) {
InIf: 100, InIf: 100,
OutIf: 200, OutIf: 200,
ExporterAddress: netip.MustParseAddr("::ffff:192.0.2.142"), ExporterAddress: netip.MustParseAddr("::ffff:192.0.2.142"),
OtherColumns: map[schema.ColumnKey]interface{}{ OtherColumns: map[schema.ColumnKey]any{
schema.ColumnExporterName: "192_0_2_142", schema.ColumnExporterName: "192_0_2_142",
schema.ColumnInIfName: "Gi0/0/100", schema.ColumnInIfName: "Gi0/0/100",
schema.ColumnOutIfName: "Gi0/0/200", schema.ColumnOutIfName: "Gi0/0/200",
@@ -107,7 +107,7 @@ func TestEnrich(t *testing.T) {
InIf: 100, InIf: 100,
OutIf: 200, OutIf: 200,
ExporterAddress: netip.MustParseAddr("::ffff:192.0.2.142"), ExporterAddress: netip.MustParseAddr("::ffff:192.0.2.142"),
OtherColumns: map[schema.ColumnKey]interface{}{ OtherColumns: map[schema.ColumnKey]any{
schema.ColumnExporterName: "192_0_2_142", schema.ColumnExporterName: "192_0_2_142",
schema.ColumnInIfName: "Gi0/0/100", schema.ColumnInIfName: "Gi0/0/100",
schema.ColumnOutIfName: "Gi0/0/200", schema.ColumnOutIfName: "Gi0/0/200",
@@ -136,7 +136,7 @@ func TestEnrich(t *testing.T) {
InIf: 100, InIf: 100,
OutIf: 200, OutIf: 200,
ExporterAddress: netip.MustParseAddr("::ffff:192.0.2.142"), ExporterAddress: netip.MustParseAddr("::ffff:192.0.2.142"),
OtherColumns: map[schema.ColumnKey]interface{}{ OtherColumns: map[schema.ColumnKey]any{
schema.ColumnExporterName: "192_0_2_142", schema.ColumnExporterName: "192_0_2_142",
schema.ColumnInIfName: "Gi0/0/100", schema.ColumnInIfName: "Gi0/0/100",
schema.ColumnOutIfName: "Gi0/0/200", schema.ColumnOutIfName: "Gi0/0/200",
@@ -168,7 +168,7 @@ func TestEnrich(t *testing.T) {
InIf: 100, InIf: 100,
OutIf: 200, OutIf: 200,
ExporterAddress: netip.MustParseAddr("::ffff:192.0.2.142"), ExporterAddress: netip.MustParseAddr("::ffff:192.0.2.142"),
OtherColumns: map[schema.ColumnKey]interface{}{ OtherColumns: map[schema.ColumnKey]any{
schema.ColumnExporterName: "192_0_2_142", schema.ColumnExporterName: "192_0_2_142",
schema.ColumnExporterRegion: "asia", schema.ColumnExporterRegion: "asia",
schema.ColumnExporterTenant: "alfred", schema.ColumnExporterTenant: "alfred",
@@ -202,7 +202,7 @@ func TestEnrich(t *testing.T) {
InIf: 100, InIf: 100,
OutIf: 200, OutIf: 200,
ExporterAddress: netip.MustParseAddr("::ffff:192.0.2.142"), ExporterAddress: netip.MustParseAddr("::ffff:192.0.2.142"),
OtherColumns: map[schema.ColumnKey]interface{}{ OtherColumns: map[schema.ColumnKey]any{
schema.ColumnExporterName: "192_0_2_142", schema.ColumnExporterName: "192_0_2_142",
schema.ColumnExporterTenant: "alfred", schema.ColumnExporterTenant: "alfred",
schema.ColumnInIfName: "Gi0/0/100", schema.ColumnInIfName: "Gi0/0/100",
@@ -266,7 +266,7 @@ func TestEnrich(t *testing.T) {
InIf: 100, InIf: 100,
OutIf: 200, OutIf: 200,
ExporterAddress: netip.MustParseAddr("::ffff:192.0.2.142"), ExporterAddress: netip.MustParseAddr("::ffff:192.0.2.142"),
OtherColumns: map[schema.ColumnKey]interface{}{ OtherColumns: map[schema.ColumnKey]any{
schema.ColumnExporterName: "192_0_2_142", schema.ColumnExporterName: "192_0_2_142",
schema.ColumnInIfProvider: "index1", schema.ColumnInIfProvider: "index1",
schema.ColumnOutIfProvider: "index2", schema.ColumnOutIfProvider: "index2",
@@ -299,7 +299,7 @@ func TestEnrich(t *testing.T) {
InIf: 100, InIf: 100,
OutIf: 200, OutIf: 200,
ExporterAddress: netip.MustParseAddr("::ffff:192.0.2.142"), ExporterAddress: netip.MustParseAddr("::ffff:192.0.2.142"),
OtherColumns: map[schema.ColumnKey]interface{}{ OtherColumns: map[schema.ColumnKey]any{
schema.ColumnExporterName: "192_0_2_142", schema.ColumnExporterName: "192_0_2_142",
schema.ColumnInIfName: "eth100", schema.ColumnInIfName: "eth100",
schema.ColumnOutIfName: "Gi0/0/200", schema.ColumnOutIfName: "Gi0/0/200",
@@ -333,7 +333,7 @@ func TestEnrich(t *testing.T) {
SrcVlan: 10, SrcVlan: 10,
DstVlan: 300, DstVlan: 300,
ExporterAddress: netip.MustParseAddr("::ffff:192.0.2.142"), ExporterAddress: netip.MustParseAddr("::ffff:192.0.2.142"),
OtherColumns: map[schema.ColumnKey]interface{}{ OtherColumns: map[schema.ColumnKey]any{
schema.ColumnExporterName: "192_0_2_142", schema.ColumnExporterName: "192_0_2_142",
schema.ColumnInIfName: "Gi0/0/100", schema.ColumnInIfName: "Gi0/0/100",
schema.ColumnOutIfName: "Gi0/0/200.300", schema.ColumnOutIfName: "Gi0/0/200.300",
@@ -368,7 +368,7 @@ ClassifyProviderRegex(Interface.Description, "^Transit: ([^ ]+)", "$1")`,
InIf: 100, InIf: 100,
OutIf: 200, OutIf: 200,
ExporterAddress: netip.MustParseAddr("::ffff:192.0.2.142"), ExporterAddress: netip.MustParseAddr("::ffff:192.0.2.142"),
OtherColumns: map[schema.ColumnKey]interface{}{ OtherColumns: map[schema.ColumnKey]any{
schema.ColumnExporterName: "192_0_2_142", schema.ColumnExporterName: "192_0_2_142",
schema.ColumnInIfName: "Gi0/0/100", schema.ColumnInIfName: "Gi0/0/100",
schema.ColumnOutIfName: "Gi0/0/200", schema.ColumnOutIfName: "Gi0/0/200",
@@ -401,7 +401,7 @@ ClassifyProviderRegex(Interface.Description, "^Transit: ([^ ]+)", "$1")`,
InIf: 100, InIf: 100,
OutIf: 200, OutIf: 200,
ExporterAddress: netip.MustParseAddr("::ffff:192.0.2.142"), ExporterAddress: netip.MustParseAddr("::ffff:192.0.2.142"),
OtherColumns: map[schema.ColumnKey]interface{}{ OtherColumns: map[schema.ColumnKey]any{
schema.ColumnExporterName: "192_0_2_142", schema.ColumnExporterName: "192_0_2_142",
schema.ColumnInIfName: "Gi0/0/100", schema.ColumnInIfName: "Gi0/0/100",
schema.ColumnOutIfName: "Gi0/0/200", schema.ColumnOutIfName: "Gi0/0/200",
@@ -434,7 +434,7 @@ ClassifyProviderRegex(Interface.Description, "^Transit: ([^ ]+)", "$1")`,
InIf: 100, InIf: 100,
OutIf: 200, OutIf: 200,
ExporterAddress: netip.MustParseAddr("::ffff:192.0.2.142"), ExporterAddress: netip.MustParseAddr("::ffff:192.0.2.142"),
OtherColumns: map[schema.ColumnKey]interface{}{ OtherColumns: map[schema.ColumnKey]any{
schema.ColumnExporterName: "192_0_2_142", schema.ColumnExporterName: "192_0_2_142",
schema.ColumnInIfName: "Gi0/0/100", schema.ColumnInIfName: "Gi0/0/100",
schema.ColumnOutIfName: "Gi0/0/200", schema.ColumnOutIfName: "Gi0/0/200",
@@ -468,7 +468,7 @@ ClassifyProviderRegex(Interface.Description, "^Transit: ([^ ]+)", "$1")`,
InIf: 100, InIf: 100,
OutIf: 200, OutIf: 200,
ExporterAddress: netip.MustParseAddr("::ffff:192.0.2.142"), ExporterAddress: netip.MustParseAddr("::ffff:192.0.2.142"),
OtherColumns: map[schema.ColumnKey]interface{}{ OtherColumns: map[schema.ColumnKey]any{
schema.ColumnExporterName: "192_0_2_142", schema.ColumnExporterName: "192_0_2_142",
schema.ColumnInIfName: "Gi0/0/100", schema.ColumnInIfName: "Gi0/0/100",
schema.ColumnOutIfName: "Gi0/0/200", schema.ColumnOutIfName: "Gi0/0/200",
@@ -507,7 +507,7 @@ ClassifyProviderRegex(Interface.Description, "^Transit: ([^ ]+)", "$1")`,
InIf: 1010, InIf: 1010,
OutIf: 2010, OutIf: 2010,
ExporterAddress: netip.MustParseAddr("::ffff:192.0.2.142"), ExporterAddress: netip.MustParseAddr("::ffff:192.0.2.142"),
OtherColumns: map[schema.ColumnKey]interface{}{ OtherColumns: map[schema.ColumnKey]any{
schema.ColumnExporterName: "192_0_2_142", schema.ColumnExporterName: "192_0_2_142",
schema.ColumnExporterGroup: "metadata group", schema.ColumnExporterGroup: "metadata group",
schema.ColumnExporterRegion: "metadata region", schema.ColumnExporterRegion: "metadata region",
@@ -553,7 +553,7 @@ ClassifyProviderRegex(Interface.Description, "^Transit: ([^ ]+)", "$1")`,
DstAS: 174, DstAS: 174,
SrcNetMask: 27, SrcNetMask: 27,
DstNetMask: 27, DstNetMask: 27,
OtherColumns: map[schema.ColumnKey]interface{}{ OtherColumns: map[schema.ColumnKey]any{
schema.ColumnExporterName: "192_0_2_142", schema.ColumnExporterName: "192_0_2_142",
schema.ColumnInIfName: "Gi0/0/100", schema.ColumnInIfName: "Gi0/0/100",
schema.ColumnOutIfName: "Gi0/0/200", schema.ColumnOutIfName: "Gi0/0/200",

View File

@@ -82,7 +82,7 @@ func TestCore(t *testing.T) {
OutIf: out, OutIf: out,
SrcAddr: netip.MustParseAddr("::ffff:67.43.156.77"), SrcAddr: netip.MustParseAddr("::ffff:67.43.156.77"),
DstAddr: netip.MustParseAddr("::ffff:2.125.160.216"), DstAddr: netip.MustParseAddr("::ffff:2.125.160.216"),
OtherColumns: map[schema.ColumnKey]interface{}{ OtherColumns: map[schema.ColumnKey]any{
schema.ColumnBytes: 6765, schema.ColumnBytes: 6765,
schema.ColumnPackets: 4, schema.ColumnPackets: 4,
schema.ColumnEType: 0x800, schema.ColumnEType: 0x800,

View File

@@ -23,7 +23,7 @@ func TestDecodeMPLSAndIPv4(t *testing.T) {
expected := schema.FlowMessage{ expected := schema.FlowMessage{
SrcAddr: netip.MustParseAddr("::ffff:10.31.0.1"), SrcAddr: netip.MustParseAddr("::ffff:10.31.0.1"),
DstAddr: netip.MustParseAddr("::ffff:10.34.0.1"), DstAddr: netip.MustParseAddr("::ffff:10.34.0.1"),
OtherColumns: map[schema.ColumnKey]interface{}{ OtherColumns: map[schema.ColumnKey]any{
schema.ColumnEType: helpers.ETypeIPv4, schema.ColumnEType: helpers.ETypeIPv4,
schema.ColumnProto: 6, schema.ColumnProto: 6,
schema.ColumnSrcPort: 11001, schema.ColumnSrcPort: 11001,
@@ -54,7 +54,7 @@ func TestDecodeVLANAndIPv6(t *testing.T) {
SrcVlan: 100, SrcVlan: 100,
SrcAddr: netip.MustParseAddr("2402:f000:1:8e01::5555"), SrcAddr: netip.MustParseAddr("2402:f000:1:8e01::5555"),
DstAddr: netip.MustParseAddr("2607:fcd0:100:2300::b108:2a6b"), DstAddr: netip.MustParseAddr("2607:fcd0:100:2300::b108:2a6b"),
OtherColumns: map[schema.ColumnKey]interface{}{ OtherColumns: map[schema.ColumnKey]any{
schema.ColumnEType: helpers.ETypeIPv6, schema.ColumnEType: helpers.ETypeIPv6,
schema.ColumnProto: 4, schema.ColumnProto: 4,
schema.ColumnIPTTL: 246, schema.ColumnIPTTL: 246,

View File

@@ -54,7 +54,7 @@ func (nd *Decoder) decodeNFv5(packet *netflowlegacy.PacketNetFlowV5, ts, sysUpti
} }
} }
func (nd *Decoder) decodeNFv9IPFIX(version uint16, obsDomainID uint32, flowSets []interface{}, samplingRateSys *samplingRateSystem, ts, sysUptime uint64, options decoder.Option, bf *schema.FlowMessage, finalize decoder.FinalizeFlowFunc) { func (nd *Decoder) decodeNFv9IPFIX(version uint16, obsDomainID uint32, flowSets []any, samplingRateSys *samplingRateSystem, ts, sysUptime uint64, options decoder.Option, bf *schema.FlowMessage, finalize decoder.FinalizeFlowFunc) {
// Look for sampling rate in option data flowsets // Look for sampling rate in option data flowsets
for _, flowSet := range flowSets { for _, flowSet := range flowSets {
switch tFlowSet := flowSet.(type) { switch tFlowSet := flowSet.(type) {

View File

@@ -97,7 +97,7 @@ type templateSystem struct {
templates netflow.NetFlowTemplateSystem templates netflow.NetFlowTemplateSystem
} }
func (s *templateSystem) AddTemplate(version uint16, obsDomainID uint32, templateID uint16, template interface{}) error { func (s *templateSystem) AddTemplate(version uint16, obsDomainID uint32, templateID uint16, template any) error {
if err := s.templates.AddTemplate(version, obsDomainID, templateID, template); err != nil { if err := s.templates.AddTemplate(version, obsDomainID, templateID, template); err != nil {
return nil return nil
} }
@@ -125,11 +125,11 @@ func (s *templateSystem) AddTemplate(version uint16, obsDomainID uint32, templat
return nil return nil
} }
func (s *templateSystem) GetTemplate(version uint16, obsDomainID uint32, templateID uint16) (interface{}, error) { func (s *templateSystem) GetTemplate(version uint16, obsDomainID uint32, templateID uint16) (any, error) {
return s.templates.GetTemplate(version, obsDomainID, templateID) return s.templates.GetTemplate(version, obsDomainID, templateID)
} }
func (s *templateSystem) RemoveTemplate(version uint16, obsDomainID uint32, templateID uint16) (interface{}, error) { func (s *templateSystem) RemoveTemplate(version uint16, obsDomainID uint32, templateID uint16) (any, error) {
return s.templates.RemoveTemplate(version, obsDomainID, templateID) return s.templates.RemoveTemplate(version, obsDomainID, templateID)
} }

View File

@@ -169,7 +169,7 @@ func DefaultModels() []Model {
// ConfigurationUnmarshallerHook normalize gnmi configuration: // ConfigurationUnmarshallerHook normalize gnmi configuration:
// - replace an occurrence of "default" in the list of models with the list of default models. // - replace an occurrence of "default" in the list of models with the list of default models.
func ConfigurationUnmarshallerHook() mapstructure.DecodeHookFunc { func ConfigurationUnmarshallerHook() mapstructure.DecodeHookFunc {
return func(from, to reflect.Value) (interface{}, error) { return func(from, to reflect.Value) (any, error) {
if from.Kind() != reflect.Map || from.IsNil() || to.Type() != reflect.TypeOf(Configuration{}) { if from.Kind() != reflect.Map || from.IsNil() || to.Type() != reflect.TypeOf(Configuration{}) {
return from.Interface(), nil return from.Interface(), nil
} }
@@ -192,7 +192,7 @@ func ConfigurationUnmarshallerHook() mapstructure.DecodeHookFunc {
val := helpers.ElemOrIdentity(modelsValue.Index(i)) val := helpers.ElemOrIdentity(modelsValue.Index(i))
if val.Kind() == reflect.String && val.String() == "defaults" { if val.Kind() == reflect.String && val.String() == "defaults" {
// We need to replace this item with the default values. // We need to replace this item with the default values.
newValue := reflect.MakeSlice(reflect.SliceOf(reflect.TypeOf(new(interface{})).Elem()), 0, 0) newValue := reflect.MakeSlice(reflect.SliceOf(reflect.TypeOf(new(any)).Elem()), 0, 0)
for j := range modelsValue.Len() { for j := range modelsValue.Len() {
if i != j { if i != j {
newValue = reflect.Append(newValue, modelsValue.Index(j)) newValue = reflect.Append(newValue, modelsValue.Index(j))

View File

@@ -22,22 +22,22 @@ func TestDefaults(t *testing.T) {
helpers.TestConfigurationDecode(t, helpers.ConfigurationDecodeCases{ helpers.TestConfigurationDecode(t, helpers.ConfigurationDecodeCases{
{ {
Description: "nil", Description: "nil",
Initial: func() interface{} { return Configuration{} }, Initial: func() any { return Configuration{} },
Configuration: func() interface{} { return nil }, Configuration: func() any { return nil },
Expected: Configuration{}, Expected: Configuration{},
SkipValidation: true, SkipValidation: true,
}, { }, {
Description: "empty", Description: "empty",
Initial: func() interface{} { return Configuration{} }, Initial: func() any { return Configuration{} },
Configuration: func() interface{} { return gin.H{} }, Configuration: func() any { return gin.H{} },
Expected: Configuration{}, Expected: Configuration{},
SkipValidation: true, SkipValidation: true,
}, { }, {
Description: "override models", Description: "override models",
Initial: func() interface{} { Initial: func() any {
return Configuration{Timeout: time.Second, MinimalRefreshInterval: time.Minute} return Configuration{Timeout: time.Second, MinimalRefreshInterval: time.Minute}
}, },
Configuration: func() interface{} { Configuration: func() any {
return gin.H{ return gin.H{
"models": []gin.H{ "models": []gin.H{
{ {
@@ -73,10 +73,10 @@ func TestDefaults(t *testing.T) {
}, },
}, { }, {
Description: "defaults only", Description: "defaults only",
Initial: func() interface{} { Initial: func() any {
return Configuration{Timeout: time.Second, MinimalRefreshInterval: time.Minute} return Configuration{Timeout: time.Second, MinimalRefreshInterval: time.Minute}
}, },
Configuration: func() interface{} { Configuration: func() any {
return gin.H{ return gin.H{
"models": []string{"defaults"}, "models": []string{"defaults"},
} }
@@ -88,12 +88,12 @@ func TestDefaults(t *testing.T) {
}, },
}, { }, {
Description: "defaults first", Description: "defaults first",
Initial: func() interface{} { Initial: func() any {
return Configuration{Timeout: time.Second, MinimalRefreshInterval: time.Minute} return Configuration{Timeout: time.Second, MinimalRefreshInterval: time.Minute}
}, },
Configuration: func() interface{} { Configuration: func() any {
return gin.H{ return gin.H{
"models": []interface{}{ "models": []any{
"defaults", "defaults",
gin.H{ gin.H{
"name": "custom", "name": "custom",
@@ -126,12 +126,12 @@ func TestDefaults(t *testing.T) {
}, },
}, { }, {
Description: "defaults last", Description: "defaults last",
Initial: func() interface{} { Initial: func() any {
return Configuration{Timeout: time.Second, MinimalRefreshInterval: time.Minute} return Configuration{Timeout: time.Second, MinimalRefreshInterval: time.Minute}
}, },
Configuration: func() interface{} { Configuration: func() any {
return gin.H{ return gin.H{
"models": []interface{}{ "models": []any{
gin.H{ gin.H{
"name": "custom", "name": "custom",
"if-index-paths": "/some/path", "if-index-paths": "/some/path",
@@ -166,12 +166,12 @@ func TestDefaults(t *testing.T) {
}, },
}, { }, {
Description: "defaults in the middle", Description: "defaults in the middle",
Initial: func() interface{} { Initial: func() any {
return Configuration{Timeout: time.Second, MinimalRefreshInterval: time.Minute} return Configuration{Timeout: time.Second, MinimalRefreshInterval: time.Minute}
}, },
Configuration: func() interface{} { Configuration: func() any {
return gin.H{ return gin.H{
"models": []interface{}{ "models": []any{
gin.H{ gin.H{
"name": "custom1", "name": "custom1",
"if-index-paths": "/some/path", "if-index-paths": "/some/path",

View File

@@ -66,7 +66,7 @@ func subscribeResponseToEvents(response *gnmi.SubscribeResponse) []event {
} }
// For JSON, we need to walk the structure to create events. We // For JSON, we need to walk the structure to create events. We
// assume that we only get simple cases: no keys, no slice. // assume that we only get simple cases: no keys, no slice.
var value interface{} var value any
if err := json.Unmarshal(jsondata, &value); err != nil { if err := json.Unmarshal(jsondata, &value); err != nil {
continue continue
} }
@@ -91,13 +91,13 @@ func subscribeResponsesToEvents(responses []*gnmi.SubscribeResponse) []event {
// jsonAppendToEvents appends the events derived from the provided event plus // jsonAppendToEvents appends the events derived from the provided event plus
// the JSON-decoded value. // the JSON-decoded value.
func jsonAppendToEvents(events []event, ev event, value interface{}) []event { func jsonAppendToEvents(events []event, ev event, value any) []event {
switch value := value.(type) { switch value := value.(type) {
default: default:
return events return events
// Slices: not handled // Slices: not handled
// Maps // Maps
case map[string]interface{}: case map[string]any:
for k, v := range value { for k, v := range value {
currentEvent := ev currentEvent := ev
currentEvent.Path = path.Join(currentEvent.Path, k) currentEvent.Path = path.Join(currentEvent.Path, k)

View File

@@ -66,7 +66,7 @@ func DefaultConfiguration() provider.Configuration {
// - convert default-community to credentials (as ::/0) // - convert default-community to credentials (as ::/0)
// - merge security parameters and communities into credentials // - merge security parameters and communities into credentials
func ConfigurationUnmarshallerHook() mapstructure.DecodeHookFunc { func ConfigurationUnmarshallerHook() mapstructure.DecodeHookFunc {
return func(from, to reflect.Value) (interface{}, error) { return func(from, to reflect.Value) (any, error) {
if from.Kind() != reflect.Map || from.IsNil() || to.Type() != reflect.TypeOf(Configuration{}) { if from.Kind() != reflect.Map || from.IsNil() || to.Type() != reflect.TypeOf(Configuration{}) {
return from.Interface(), nil return from.Interface(), nil
} }

View File

@@ -22,14 +22,14 @@ func TestConfigurationUnmarshallerHook(t *testing.T) {
helpers.TestConfigurationDecode(t, helpers.ConfigurationDecodeCases{ helpers.TestConfigurationDecode(t, helpers.ConfigurationDecodeCases{
{ {
Description: "nil", Description: "nil",
Initial: func() interface{} { return Configuration{} }, Initial: func() any { return Configuration{} },
Configuration: func() interface{} { return nil }, Configuration: func() any { return nil },
Expected: Configuration{}, Expected: Configuration{},
SkipValidation: true, SkipValidation: true,
}, { }, {
Description: "empty", Description: "empty",
Initial: func() interface{} { return Configuration{} }, Initial: func() any { return Configuration{} },
Configuration: func() interface{} { return gin.H{} }, Configuration: func() any { return gin.H{} },
Expected: Configuration{ Expected: Configuration{
Credentials: helpers.MustNewSubnetMap(map[string]Credentials{ Credentials: helpers.MustNewSubnetMap(map[string]Credentials{
"::/0": {Communities: []string{"public"}}, "::/0": {Communities: []string{"public"}},
@@ -38,8 +38,8 @@ func TestConfigurationUnmarshallerHook(t *testing.T) {
SkipValidation: true, SkipValidation: true,
}, { }, {
Description: "single port", Description: "single port",
Initial: func() interface{} { return Configuration{} }, Initial: func() any { return Configuration{} },
Configuration: func() interface{} { Configuration: func() any {
return gin.H{ return gin.H{
"poller-timeout": "200ms", "poller-timeout": "200ms",
"ports": "1161", "ports": "1161",
@@ -56,8 +56,8 @@ func TestConfigurationUnmarshallerHook(t *testing.T) {
}, },
}, { }, {
Description: "per-prefix port", Description: "per-prefix port",
Initial: func() interface{} { return Configuration{} }, Initial: func() any { return Configuration{} },
Configuration: func() interface{} { Configuration: func() any {
return gin.H{ return gin.H{
"poller-timeout": "200ms", "poller-timeout": "200ms",
"ports": gin.H{ "ports": gin.H{
@@ -78,8 +78,8 @@ func TestConfigurationUnmarshallerHook(t *testing.T) {
}, },
}, { }, {
Description: "no communities, no default community", Description: "no communities, no default community",
Initial: func() interface{} { return Configuration{} }, Initial: func() any { return Configuration{} },
Configuration: func() interface{} { Configuration: func() any {
return gin.H{ return gin.H{
"poller-retries": 10, "poller-retries": 10,
"poller-timeout": "200ms", "poller-timeout": "200ms",
@@ -94,8 +94,8 @@ func TestConfigurationUnmarshallerHook(t *testing.T) {
}, },
}, { }, {
Description: "communities, no default community", Description: "communities, no default community",
Initial: func() interface{} { return Configuration{} }, Initial: func() any { return Configuration{} },
Configuration: func() interface{} { Configuration: func() any {
return gin.H{ return gin.H{
"poller-timeout": "200ms", "poller-timeout": "200ms",
"communities": gin.H{ "communities": gin.H{
@@ -114,8 +114,8 @@ func TestConfigurationUnmarshallerHook(t *testing.T) {
}, },
}, { }, {
Description: "communities, default community", Description: "communities, default community",
Initial: func() interface{} { return Configuration{} }, Initial: func() any { return Configuration{} },
Configuration: func() interface{} { Configuration: func() any {
return gin.H{ return gin.H{
"poller-timeout": "200ms", "poller-timeout": "200ms",
"default-community": "private", "default-community": "private",
@@ -135,8 +135,8 @@ func TestConfigurationUnmarshallerHook(t *testing.T) {
}, },
}, { }, {
Description: "communities as a string", Description: "communities as a string",
Initial: func() interface{} { return Configuration{} }, Initial: func() any { return Configuration{} },
Configuration: func() interface{} { Configuration: func() any {
return gin.H{ return gin.H{
"poller-timeout": "200ms", "poller-timeout": "200ms",
"communities": "private", "communities": "private",
@@ -150,8 +150,8 @@ func TestConfigurationUnmarshallerHook(t *testing.T) {
}, },
}, { }, {
Description: "communities, default-community empty", Description: "communities, default-community empty",
Initial: func() interface{} { return Configuration{} }, Initial: func() any { return Configuration{} },
Configuration: func() interface{} { Configuration: func() any {
return gin.H{ return gin.H{
"poller-timeout": "200ms", "poller-timeout": "200ms",
"default-community": "", "default-community": "",
@@ -171,8 +171,8 @@ func TestConfigurationUnmarshallerHook(t *testing.T) {
}, },
}, { }, {
Description: "SNMP security parameters", Description: "SNMP security parameters",
Initial: func() interface{} { return Configuration{} }, Initial: func() any { return Configuration{} },
Configuration: func() interface{} { Configuration: func() any {
return gin.H{ return gin.H{
"poller-timeout": "200ms", "poller-timeout": "200ms",
"security-parameters": gin.H{ "security-parameters": gin.H{
@@ -198,8 +198,8 @@ func TestConfigurationUnmarshallerHook(t *testing.T) {
}, },
}, { }, {
Description: "SNMP security parameters with AES256C", Description: "SNMP security parameters with AES256C",
Initial: func() interface{} { return Configuration{} }, Initial: func() any { return Configuration{} },
Configuration: func() interface{} { Configuration: func() any {
return gin.H{ return gin.H{
"poller-timeout": "200ms", "poller-timeout": "200ms",
"security-parameters": gin.H{ "security-parameters": gin.H{
@@ -225,8 +225,8 @@ func TestConfigurationUnmarshallerHook(t *testing.T) {
}, },
}, { }, {
Description: "SNMP security parameters without privacy protocol", Description: "SNMP security parameters without privacy protocol",
Initial: func() interface{} { return Configuration{} }, Initial: func() any { return Configuration{} },
Configuration: func() interface{} { Configuration: func() any {
return gin.H{ return gin.H{
"poller-timeout": "200ms", "poller-timeout": "200ms",
"security-parameters": gin.H{ "security-parameters": gin.H{
@@ -248,8 +248,8 @@ func TestConfigurationUnmarshallerHook(t *testing.T) {
}, },
}, { }, {
Description: "SNMP security parameters without authentication protocol", Description: "SNMP security parameters without authentication protocol",
Initial: func() interface{} { return Configuration{} }, Initial: func() any { return Configuration{} },
Configuration: func() interface{} { Configuration: func() any {
return gin.H{ return gin.H{
"poller-timeout": "200ms", "poller-timeout": "200ms",
"security-parameters": gin.H{ "security-parameters": gin.H{
@@ -262,8 +262,8 @@ func TestConfigurationUnmarshallerHook(t *testing.T) {
Error: true, Error: true,
}, { }, {
Description: "SNMP security parameters without authentication passphrase", Description: "SNMP security parameters without authentication passphrase",
Initial: func() interface{} { return Configuration{} }, Initial: func() any { return Configuration{} },
Configuration: func() interface{} { Configuration: func() any {
return gin.H{ return gin.H{
"poller-timeout": "200ms", "poller-timeout": "200ms",
"security-parameters": gin.H{ "security-parameters": gin.H{
@@ -275,8 +275,8 @@ func TestConfigurationUnmarshallerHook(t *testing.T) {
Error: true, Error: true,
}, { }, {
Description: "SNMP security parameters without username", Description: "SNMP security parameters without username",
Initial: func() interface{} { return Configuration{} }, Initial: func() any { return Configuration{} },
Configuration: func() interface{} { Configuration: func() any {
return gin.H{ return gin.H{
"poller-timeout": "200ms", "poller-timeout": "200ms",
"credentials": gin.H{ "credentials": gin.H{
@@ -290,8 +290,8 @@ func TestConfigurationUnmarshallerHook(t *testing.T) {
Error: true, Error: true,
}, { }, {
Description: "merge communities and security-parameters", Description: "merge communities and security-parameters",
Initial: func() interface{} { return Configuration{} }, Initial: func() any { return Configuration{} },
Configuration: func() interface{} { Configuration: func() any {
return gin.H{ return gin.H{
"poller-timeout": "200ms", "poller-timeout": "200ms",
"communities": gin.H{ "communities": gin.H{
@@ -321,8 +321,8 @@ func TestConfigurationUnmarshallerHook(t *testing.T) {
}, },
}, { }, {
Description: "merge communities, security-parameters and credentials", Description: "merge communities, security-parameters and credentials",
Initial: func() interface{} { return Configuration{} }, Initial: func() any { return Configuration{} },
Configuration: func() interface{} { Configuration: func() any {
return gin.H{ return gin.H{
"poller-timeout": "200ms", "poller-timeout": "200ms",
"communities": gin.H{ "communities": gin.H{
@@ -358,8 +358,8 @@ func TestConfigurationUnmarshallerHook(t *testing.T) {
}, },
}, { }, {
Description: "merge communities, security-parameters and default credentials", Description: "merge communities, security-parameters and default credentials",
Initial: func() interface{} { return Configuration{} }, Initial: func() any { return Configuration{} },
Configuration: func() interface{} { Configuration: func() any {
return gin.H{ return gin.H{
"poller-timeout": "200ms", "poller-timeout": "200ms",
"communities": gin.H{ "communities": gin.H{
@@ -393,8 +393,8 @@ func TestConfigurationUnmarshallerHook(t *testing.T) {
}, },
}, { }, {
Description: "conflicting SNMP version", Description: "conflicting SNMP version",
Initial: func() interface{} { return Configuration{} }, Initial: func() any { return Configuration{} },
Configuration: func() interface{} { Configuration: func() any {
return gin.H{ return gin.H{
"poller-timeout": "200ms", "poller-timeout": "200ms",
"credentials": gin.H{ "credentials": gin.H{

View File

@@ -215,13 +215,13 @@ type goSNMPLogger struct {
r *reporter.Reporter r *reporter.Reporter
} }
func (l *goSNMPLogger) Print(v ...interface{}) { func (l *goSNMPLogger) Print(v ...any) {
if e := l.r.Debug(); e.Enabled() { if e := l.r.Debug(); e.Enabled() {
e.Msg(fmt.Sprint(v...)) e.Msg(fmt.Sprint(v...))
} }
} }
func (l *goSNMPLogger) Printf(format string, v ...interface{}) { func (l *goSNMPLogger) Printf(format string, v ...any) {
if e := l.r.Debug(); e.Enabled() { if e := l.r.Debug(); e.Enabled() {
e.Msg(fmt.Sprintf(format, v...)) e.Msg(fmt.Sprintf(format, v...))
} }

View File

@@ -143,91 +143,91 @@ func TestPoller(t *testing.T) {
{ {
OID: "1.3.6.1.2.1.1.5.0", OID: "1.3.6.1.2.1.1.5.0",
Type: gosnmp.OctetString, Type: gosnmp.OctetString,
OnGet: func() (interface{}, error) { OnGet: func() (any, error) {
return "exporter62", nil return "exporter62", nil
}, },
}, { }, {
OID: "1.3.6.1.2.1.2.2.1.2.641", OID: "1.3.6.1.2.1.2.2.1.2.641",
Type: gosnmp.OctetString, Type: gosnmp.OctetString,
OnGet: func() (interface{}, error) { OnGet: func() (any, error) {
return "Gi0/0/0/0", nil return "Gi0/0/0/0", nil
}, },
}, { }, {
OID: "1.3.6.1.2.1.2.2.1.2.642", OID: "1.3.6.1.2.1.2.2.1.2.642",
Type: gosnmp.OctetString, Type: gosnmp.OctetString,
OnGet: func() (interface{}, error) { OnGet: func() (any, error) {
return "Gi0/0/0/1", nil return "Gi0/0/0/1", nil
}, },
}, { }, {
OID: "1.3.6.1.2.1.2.2.1.2.643", OID: "1.3.6.1.2.1.2.2.1.2.643",
Type: gosnmp.OctetString, Type: gosnmp.OctetString,
OnGet: func() (interface{}, error) { OnGet: func() (any, error) {
return "Gi0/0/0/2", nil return "Gi0/0/0/2", nil
}, },
}, { }, {
OID: "1.3.6.1.2.1.2.2.1.2.645", OID: "1.3.6.1.2.1.2.2.1.2.645",
Type: gosnmp.OctetString, Type: gosnmp.OctetString,
OnGet: func() (interface{}, error) { OnGet: func() (any, error) {
return "Correct description", nil return "Correct description", nil
}, },
}, { }, {
OID: "1.3.6.1.2.1.31.1.1.1.1.641", OID: "1.3.6.1.2.1.31.1.1.1.1.641",
Type: gosnmp.OctetString, Type: gosnmp.OctetString,
OnGet: func() (interface{}, error) { OnGet: func() (any, error) {
return "Gi0/0/0/0", nil return "Gi0/0/0/0", nil
}, },
}, { }, {
OID: "1.3.6.1.2.1.31.1.1.1.1.642", OID: "1.3.6.1.2.1.31.1.1.1.1.642",
Type: gosnmp.OctetString, Type: gosnmp.OctetString,
OnGet: func() (interface{}, error) { OnGet: func() (any, error) {
return "Gi0/0/0/1", nil return "Gi0/0/0/1", nil
}, },
}, { }, {
OID: "1.3.6.1.2.1.31.1.1.1.1.643", OID: "1.3.6.1.2.1.31.1.1.1.1.643",
Type: gosnmp.OctetString, Type: gosnmp.OctetString,
OnGet: func() (interface{}, error) { OnGet: func() (any, error) {
return "Gi0/0/0/2", nil return "Gi0/0/0/2", nil
}, },
}, { }, {
OID: "1.3.6.1.2.1.31.1.1.1.1.645", OID: "1.3.6.1.2.1.31.1.1.1.1.645",
Type: gosnmp.OctetString, Type: gosnmp.OctetString,
OnGet: func() (interface{}, error) { OnGet: func() (any, error) {
return "Gi0/0/0/5", nil return "Gi0/0/0/5", nil
}, },
}, { }, {
OID: "1.3.6.1.2.1.31.1.1.1.15.641", OID: "1.3.6.1.2.1.31.1.1.1.15.641",
Type: gosnmp.Gauge32, Type: gosnmp.Gauge32,
OnGet: func() (interface{}, error) { OnGet: func() (any, error) {
return uint(10000), nil return uint(10000), nil
}, },
}, { }, {
OID: "1.3.6.1.2.1.31.1.1.1.15.642", OID: "1.3.6.1.2.1.31.1.1.1.15.642",
Type: gosnmp.Gauge32, Type: gosnmp.Gauge32,
OnGet: func() (interface{}, error) { OnGet: func() (any, error) {
return uint(20000), nil return uint(20000), nil
}, },
}, { }, {
OID: "1.3.6.1.2.1.31.1.1.1.15.643", OID: "1.3.6.1.2.1.31.1.1.1.15.643",
Type: gosnmp.Gauge32, Type: gosnmp.Gauge32,
OnGet: func() (interface{}, error) { OnGet: func() (any, error) {
return uint(10000), nil return uint(10000), nil
}, },
}, { }, {
OID: "1.3.6.1.2.1.31.1.1.1.15.645", OID: "1.3.6.1.2.1.31.1.1.1.15.645",
Type: gosnmp.Gauge32, Type: gosnmp.Gauge32,
OnGet: func() (interface{}, error) { OnGet: func() (any, error) {
return uint(1000), nil return uint(1000), nil
}, },
}, { }, {
OID: "1.3.6.1.2.1.31.1.1.1.18.641", OID: "1.3.6.1.2.1.31.1.1.1.18.641",
Type: gosnmp.OctetString, Type: gosnmp.OctetString,
OnGet: func() (interface{}, error) { OnGet: func() (any, error) {
return "Transit", nil return "Transit", nil
}, },
}, { }, {
OID: "1.3.6.1.2.1.31.1.1.1.18.642", OID: "1.3.6.1.2.1.31.1.1.1.18.642",
Type: gosnmp.OctetString, Type: gosnmp.OctetString,
OnGet: func() (interface{}, error) { OnGet: func() (any, error) {
return "Peering", nil return "Peering", nil
}, },
}, },
@@ -235,7 +235,7 @@ func TestPoller(t *testing.T) {
{ {
OID: "1.3.6.1.2.1.31.1.1.1.18.645", OID: "1.3.6.1.2.1.31.1.1.1.18.645",
Type: gosnmp.OctetString, Type: gosnmp.OctetString,
OnGet: func() (interface{}, error) { OnGet: func() (any, error) {
return "Gi0/0/0/5", nil return "Gi0/0/0/5", nil
}, },
}, },

View File

@@ -28,7 +28,7 @@ type ProviderConfiguration struct {
} }
// MarshalYAML undoes ConfigurationUnmarshallerHook(). // MarshalYAML undoes ConfigurationUnmarshallerHook().
func (pc ProviderConfiguration) MarshalYAML() (interface{}, error) { func (pc ProviderConfiguration) MarshalYAML() (any, error) {
return helpers.ParametrizedConfigurationMarshalYAML(pc, providers) return helpers.ParametrizedConfigurationMarshalYAML(pc, providers)
} }