diff --git a/cmd/components.go b/cmd/components.go index 539b39e5..9358f885 100644 --- a/cmd/components.go +++ b/cmd/components.go @@ -12,9 +12,9 @@ import ( ) // StartStopComponents activate/deactivate components in order. -func StartStopComponents(r *reporter.Reporter, daemonComponent daemon.Component, otherComponents []interface{}) error { - components := append([]interface{}{r, daemonComponent}, otherComponents...) - startedComponents := []interface{}{} +func StartStopComponents(r *reporter.Reporter, daemonComponent daemon.Component, otherComponents []any) error { + components := append([]any{r, daemonComponent}, otherComponents...) + startedComponents := []any{} defer func() { for _, cmp := range startedComponents { 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) } } - startedComponents = append([]interface{}{cmp}, startedComponents...) + startedComponents = append([]any{cmp}, startedComponents...) } r.Info(). diff --git a/cmd/components_test.go b/cmd/components_test.go index c5791208..bed85dc6 100644 --- a/cmd/components_test.go +++ b/cmd/components_test.go @@ -55,7 +55,7 @@ func (c ComponentStartError) Start() error { func TestStartStopError(t *testing.T) { r := reporter.NewMock(t) daemonComponent := daemon.NewMock(t) - otherComponents := []interface{}{ + otherComponents := []any{ &ComponentStartStop{}, &ComponentStop{}, &ComponentStart{}, @@ -67,7 +67,7 @@ func TestStartStopError(t *testing.T) { t.Error("StartStopComponents() did not trigger an error") } - expected := []interface{}{ + expected := []any{ &ComponentStartStop{ Startable: Startable{Started: true}, Stopable: Stopable{Stopped: true}, @@ -90,7 +90,7 @@ func TestStartStopError(t *testing.T) { func TestStartStop(t *testing.T) { r := reporter.NewMock(t) daemonComponent := daemon.NewMock(t) - otherComponents := []interface{}{ + otherComponents := []any{ &ComponentStartStop{}, &ComponentStop{}, &ComponentStart{}, @@ -104,7 +104,7 @@ func TestStartStop(t *testing.T) { t.Errorf("StartStopComponents() error:\n%+v", err) } - expected := []interface{}{ + expected := []any{ &ComponentStartStop{ Startable: Startable{Started: true}, Stopable: Stopable{Stopped: true}, diff --git a/cmd/config.go b/cmd/config.go index ce229ee7..7b544d7e 100644 --- a/cmd/config.go +++ b/cmd/config.go @@ -35,7 +35,7 @@ type ConfigRelatedOptions struct { // Parse parses the configuration file (if present) and the // 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 if cfgFile := c.Path; cfgFile != "" { 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 -> // 47". From AKVORADO_CFG_CMP_SQUID_3_PURPLE=47, we // build "squid[3] -> purple -> 47" - var rawConfig interface{} + var rawConfig any rawConfig = kv[1] for i := len(kk) - 1; i > 2; i-- { if index, err := strconv.Atoi(kk[i]); err == nil { - newRawConfig := make([]interface{}, index+1) + newRawConfig := make([]any, index+1) newRawConfig[index] = rawConfig rawConfig = newRawConfig } else { @@ -171,7 +171,7 @@ func (c ConfigRelatedOptions) Parse(out io.Writer, component string, config inte // the Reset() method if present. func DefaultHook() (mapstructure.DecodeHookFunc, func()) { disabled := false - hook := func(from, to reflect.Value) (interface{}, error) { + hook := func(from, to reflect.Value) (any, error) { if disabled { return from.Interface(), nil } @@ -217,7 +217,7 @@ func DefaultHook() (mapstructure.DecodeHookFunc, func()) { // non-nil slice. Like DefaultHook, it can be disabled. func ZeroSliceHook() (mapstructure.DecodeHookFunc, func()) { disabled := false - hook := func(from, to reflect.Value) (interface{}, error) { + hook := func(from, to reflect.Value) (any, error) { if disabled { return from.Interface(), nil } diff --git a/cmd/config_test.go b/cmd/config_test.go index a61ce863..40ef643d 100644 --- a/cmd/config_test.go +++ b/cmd/config_test.go @@ -170,7 +170,7 @@ module2: "workers": 5, "intervalvalue": "20m0s", }, - "elements": []interface{}{ + "elements": []any{ gin.H{ "name": "first", "gauge": 67, @@ -356,7 +356,7 @@ invalid key "unused"`); diff != "" { } 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 config := `--- modules: @@ -434,7 +434,7 @@ modules: } } 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 { Modules []dummyConfiguration }{} @@ -445,7 +445,7 @@ modules: }) }) 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 { Modules []*dummyConfiguration }{} diff --git a/cmd/conntrack-fixer.go b/cmd/conntrack-fixer.go index cc0b1b1e..080e4ecd 100644 --- a/cmd/conntrack-fixer.go +++ b/cmd/conntrack-fixer.go @@ -51,7 +51,7 @@ containers started with the label "akvorado.conntrack.fix=1".`, addCommonHTTPHandlers(r, "conntrack-fixer", httpComponent) versionMetrics(r) - components := []interface{}{ + components := []any{ httpComponent, conntrackFixerComponent, } diff --git a/cmd/console.go b/cmd/console.go index c15f2388..2338a194 100644 --- a/cmd/console.go +++ b/cmd/console.go @@ -131,7 +131,7 @@ func consoleStart(r *reporter.Reporter, config ConsoleConfiguration, checkOnly b } // Start all the components. - components := []interface{}{ + components := []any{ httpComponent, clickhouseComponent, authenticationComponent, diff --git a/cmd/demo-exporter.go b/cmd/demo-exporter.go index ab1a68d3..18b7284a 100644 --- a/cmd/demo-exporter.go +++ b/cmd/demo-exporter.go @@ -124,7 +124,7 @@ func demoExporterStart(r *reporter.Reporter, config DemoExporterConfiguration, c } // Start all the components. - components := []interface{}{ + components := []any{ httpComponent, snmpComponent, bmpComponent, diff --git a/cmd/inlet.go b/cmd/inlet.go index 9a25588c..34d111a1 100644 --- a/cmd/inlet.go +++ b/cmd/inlet.go @@ -108,7 +108,7 @@ func inletStart(r *reporter.Reporter, config InletConfiguration, checkOnly bool) } // Start all the components. - components := []interface{}{ + components := []any{ httpComponent, kafkaComponent, flowComponent, diff --git a/cmd/orchestrator_test.go b/cmd/orchestrator_test.go index 3d7819e0..01a9a4d3 100644 --- a/cmd/orchestrator_test.go +++ b/cmd/orchestrator_test.go @@ -42,7 +42,7 @@ func TestOrchestratorConfig(t *testing.T) { t.Fatalf("ReadFile() error:\n%+v", err) } var expectedYAML struct { - Paths map[string]interface{} `yaml:"paths"` + Paths map[string]any `yaml:"paths"` } if err := yaml.Unmarshal(expected, &expectedYAML); err != nil { t.Fatalf("yaml.Unmarshal(expected) error:\n%+v", err) @@ -57,30 +57,30 @@ func TestOrchestratorConfig(t *testing.T) { if err := root.Execute(); err != nil { 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 { t.Fatalf("yaml.Unmarshal(output) error:\n%+v", err) } for path, expected := range expectedYAML.Paths { - var got interface{} + var got any got = gotYAML i := 0 for _, component := range strings.Split(path, ".") { var ok bool i++ switch gotConcrete := got.(type) { - case []interface{}: + case []any: index, err := strconv.Atoi(component) if err != nil { t.Fatalf("key %q at level %d should be an int", path, i) } got = gotConcrete[index] - case map[interface{}]interface{}: + case map[any]any: got, ok = gotConcrete[component] if !ok { t.Fatalf("key %q does not exist in result", path) } - case map[string]interface{}: + case map[string]any: got, ok = gotConcrete[component] if !ok { t.Fatalf("key %q does not exist in result", path) diff --git a/cmd/outlet.go b/cmd/outlet.go index 97780883..17414f5b 100644 --- a/cmd/outlet.go +++ b/cmd/outlet.go @@ -188,7 +188,7 @@ func outletStart(r *reporter.Reporter, config OutletConfiguration, checkOnly boo // OutletConfigurationUnmarshallerHook renames SNMP configuration to metadata and // BMP configuration to routing. 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{}) { return from.Interface(), nil } diff --git a/common/clickhousedb/root_test.go b/common/clickhousedb/root_test.go index bd3b932f..77934df5 100644 --- a/common/clickhousedb/root_test.go +++ b/common/clickhousedb/root_test.go @@ -58,7 +58,7 @@ func TestMock(t *testing.T) { Return(mockRows, nil) mockRows.EXPECT().Next().Return(true) 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 = uint64(10) arg1 := args[1].(*uint64) diff --git a/common/helpers/mapstructure.go b/common/helpers/mapstructure.go index 07fadde4..b725f900 100644 --- a/common/helpers/mapstructure.go +++ b/common/helpers/mapstructure.go @@ -75,7 +75,7 @@ func SameTypeOrSuperset(input, ref reflect.Type) bool { // GetMapStructureDecoderConfig returns a decoder config for // mapstructure with all registered hooks as well as appropriate // default configuration. -func GetMapStructureDecoderConfig(config interface{}, hooks ...mapstructure.DecodeHookFunc) *mapstructure.DecoderConfig { +func GetMapStructureDecoderConfig(config any, hooks ...mapstructure.DecodeHookFunc) *mapstructure.DecoderConfig { return &mapstructure.DecoderConfig{ Result: config, ErrorUnused: true, @@ -99,8 +99,8 @@ func StringToSliceHookFunc(sep string) mapstructure.DecodeHookFunc { return func( f reflect.Kind, t reflect.Kind, - data interface{}, - ) (interface{}, error) { + data any, + ) (any, error) { if f != reflect.String || t != reflect.Slice { 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. 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() { if r := recover(); r != nil { v = nil @@ -137,7 +137,7 @@ func MapStructureMatchName(mapKey, fieldName string) bool { // DefaultValuesUnmarshallerHook adds default values from the provided // configuration. For each missing non-default key, it will add them. 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) to = ElemOrIdentity(to) 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. 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) { 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 // default config should be provided. 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) { return from.Interface(), nil } @@ -306,7 +306,7 @@ func ParametrizedConfigurationUnmarshallerHook[OuterConfiguration any, InnerConf } // 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 outerConfigStruct := ElemOrIdentity(reflect.ValueOf(oc)) result := gin.H{} diff --git a/common/helpers/mapstructure_test.go b/common/helpers/mapstructure_test.go index e97e5f63..2352ad00 100644 --- a/common/helpers/mapstructure_test.go +++ b/common/helpers/mapstructure_test.go @@ -44,8 +44,8 @@ func TestStringToSliceHookFunc(t *testing.T) { } TestConfigurationDecode(t, ConfigurationDecodeCases{ { - Initial: func() interface{} { return Configuration{} }, - Configuration: func() interface{} { + Initial: func() any { return Configuration{} }, + Configuration: func() any { return gin.H{ "a": "blip,blop", "b": "1,2,3,4", @@ -64,7 +64,7 @@ func TestProtectedDecodeHook(t *testing.T) { A 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 { panic(errors.New("noooo")) } @@ -106,8 +106,8 @@ func TestDefaultValuesConfig(t *testing.T) { })) TestConfigurationDecode(t, ConfigurationDecodeCases{ { - Initial: func() interface{} { return OuterConfiguration{} }, - Configuration: func() interface{} { + Initial: func() any { return OuterConfiguration{} }, + Configuration: func() any { return gin.H{ "dd": []gin.H{ { @@ -150,8 +150,8 @@ func TestRenameConfig(t *testing.T) { TestConfigurationDecode(t, ConfigurationDecodeCases{ { Description: "no rename needed", - Initial: func() interface{} { return Configuration{} }, - Configuration: func() interface{} { + Initial: func() any { return Configuration{} }, + Configuration: func() any { return gin.H{ "unchanged-label": "hello", "new-label": "bye", @@ -163,8 +163,8 @@ func TestRenameConfig(t *testing.T) { }, }, { Description: "rename needed", - Initial: func() interface{} { return Configuration{} }, - Configuration: func() interface{} { + Initial: func() any { return Configuration{} }, + Configuration: func() any { return gin.H{ "unchanged-label": "hello", "old-label": "bye", @@ -176,8 +176,8 @@ func TestRenameConfig(t *testing.T) { }, }, { Description: "conflicts", - Initial: func() interface{} { return Configuration{} }, - Configuration: func() interface{} { + Initial: func() any { return Configuration{} }, + Configuration: func() any { return gin.H{ "unchanged-label": "hello", "old-label": "bye", @@ -201,16 +201,16 @@ func TestParametrizedConfig(t *testing.T) { type OuterConfiguration struct { AA string BB string - Config interface{} + Config any } - available := map[string](func() interface{}){ - "type1": func() interface{} { + available := map[string](func() any){ + "type1": func() any { return InnerConfigurationType1{ CC: "cc1", DD: "dd1", } }, - "type2": func() interface{} { + "type2": func() any { return InnerConfigurationType2{ CC: "cc2", EE: "ee2", @@ -223,8 +223,8 @@ func TestParametrizedConfig(t *testing.T) { TestConfigurationDecode(t, ConfigurationDecodeCases{ { Description: "type1", - Initial: func() interface{} { return OuterConfiguration{} }, - Configuration: func() interface{} { + Initial: func() any { return OuterConfiguration{} }, + Configuration: func() any { return gin.H{ "type": "type1", "aa": "a1", @@ -243,8 +243,8 @@ func TestParametrizedConfig(t *testing.T) { }, }, { Description: "type2", - Initial: func() interface{} { return OuterConfiguration{} }, - Configuration: func() interface{} { + Initial: func() any { return OuterConfiguration{} }, + Configuration: func() any { return gin.H{ "type": "type2", "aa": "a2", @@ -263,8 +263,8 @@ func TestParametrizedConfig(t *testing.T) { }, }, { Description: "unknown type", - Initial: func() interface{} { return OuterConfiguration{} }, - Configuration: func() interface{} { + Initial: func() any { return OuterConfiguration{} }, + Configuration: func() any { return gin.H{ "type": "type3", "aa": "a2", @@ -345,8 +345,8 @@ func TestDeprecatedFields(t *testing.T) { RegisterMapstructureDeprecatedFields[Configuration]("C", "D") TestConfigurationDecode(t, ConfigurationDecodeCases{ { - Initial: func() interface{} { return Configuration{} }, - Configuration: func() interface{} { + Initial: func() any { return Configuration{} }, + Configuration: func() any { return gin.H{ "a": "hello", "b": "bye", @@ -359,8 +359,8 @@ func TestDeprecatedFields(t *testing.T) { B: "bye", }, }, { - Initial: func() interface{} { return Configuration{} }, - Configuration: func() interface{} { + Initial: func() any { return Configuration{} }, + Configuration: func() any { return gin.H{ "a": "hello", "b": "bye", diff --git a/common/helpers/subnetmap.go b/common/helpers/subnetmap.go index 8e8a486c..415f0ae7 100644 --- a/common/helpers/subnetmap.go +++ b/common/helpers/subnetmap.go @@ -161,7 +161,7 @@ func LooksLikeSubnetMap(v reflect.Value) (result bool) { // valid networks are provided as key. It also accepts a single value // instead of a map for backward compatibility. 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]{}) { 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. -func (sm SubnetMap[V]) MarshalYAML() (interface{}, error) { +func (sm SubnetMap[V]) MarshalYAML() (any, error) { return sm.ToMap(), nil } diff --git a/common/helpers/subnetmap_test.go b/common/helpers/subnetmap_test.go index 0e3db8b4..17d9832e 100644 --- a/common/helpers/subnetmap_test.go +++ b/common/helpers/subnetmap_test.go @@ -19,10 +19,10 @@ func TestSubnetMapUnmarshalHook(t *testing.T) { var nilMap map[string]string cases := []struct { Description string - Input interface{} + Input any Tests map[string]string Error bool - YAML interface{} + YAML any }{ { Description: "nil", diff --git a/common/helpers/tests.go b/common/helpers/tests.go index 85a90bf6..cea06d15 100644 --- a/common/helpers/tests.go +++ b/common/helpers/tests.go @@ -79,7 +79,7 @@ func CheckExternalService(t *testing.T, name string, candidates []string) string } // 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() if starterC, ok := component.(starter); ok { if err := starterC.Start(); err != nil { diff --git a/common/helpers/tests_config.go b/common/helpers/tests_config.go index 3d14f4d9..07a59d2e 100644 --- a/common/helpers/tests_config.go +++ b/common/helpers/tests_config.go @@ -20,9 +20,9 @@ import ( type ConfigurationDecodeCases []struct { Description string Pos Pos - Initial func() interface{} // initial value for configuration - Configuration func() interface{} // configuration to decode - Expected interface{} + Initial func() any // initial value for configuration + Configuration func() any // configuration to decode + Expected any Error bool SkipValidation bool } @@ -41,7 +41,7 @@ func TestConfigurationDecode(t *testing.T, cases ConfigurationDecodeCases, optio } t.Run(title, func(t *testing.T) { t.Helper() - var configuration interface{} + var configuration any if fromYAML { // Encode and decode with YAML out, err := yaml.Marshal(tc.Configuration()) diff --git a/common/helpers/tests_diff.go b/common/helpers/tests_diff.go index 45ecb84b..f0bff2af 100644 --- a/common/helpers/tests_diff.go +++ b/common/helpers/tests_diff.go @@ -22,12 +22,12 @@ var prettyC = pretty.Config{ IncludeUnexported: false, } -func formatByte(v interface{}) string { +func formatByte(v any) string { return fmt.Sprintf("0x%x", v) } -func defaultPrettyFormatters() map[reflect.Type]interface{} { - result := map[reflect.Type]interface{}{ +func defaultPrettyFormatters() map[reflect.Type]any { + result := map[reflect.Type]any{ reflect.TypeOf(net.IP{}): fmt.Sprint, reflect.TypeOf(netip.Addr{}): fmt.Sprint, reflect.TypeOf(time.Time{}): fmt.Sprint, @@ -42,11 +42,11 @@ func defaultPrettyFormatters() map[reflect.Type]interface{} { 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 // the default map due to cycles. -func AddPrettyFormatter(t reflect.Type, fn interface{}) { +func AddPrettyFormatter(t reflect.Type, fn any) { nonDefaultPrettyFormatters[t] = fn } @@ -55,12 +55,12 @@ type DiffOption struct { kind int // When this is a formatter t reflect.Type - fn interface{} + fn any } // Diff return a diff of two objects. If no diff, an empty string is // returned. -func Diff(a, b interface{}, options ...DiffOption) string { +func Diff(a, b any, options ...DiffOption) string { prettyC := prettyC prettyC.Formatter = defaultPrettyFormatters() for _, option := range options { @@ -84,6 +84,6 @@ var ( ) // 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} } diff --git a/common/helpers/tests_http.go b/common/helpers/tests_http.go index af0e1594..08d2d28a 100644 --- a/common/helpers/tests_http.go +++ b/common/helpers/tests_http.go @@ -24,12 +24,12 @@ type HTTPEndpointCases []struct { Method string URL string Header http.Header - JSONInput interface{} + JSONInput any ContentType string StatusCode int FirstLines []string - JSONOutput interface{} + JSONOutput any } // TestHTTPEndpoints test a few HTTP endpoints diff --git a/common/helpers/validator.go b/common/helpers/validator.go index 39ae399e..abb2d17b 100644 --- a/common/helpers/validator.go +++ b/common/helpers/validator.go @@ -20,7 +20,7 @@ var Validate *validator.Validate // register all subnetmaps. func RegisterSubnetMapValidation[V any]() { var zero SubnetMap[V] - validatorFunc := func(field reflect.Value) interface{} { + validatorFunc := func(field reflect.Value) any { switch subnetMap := field.Interface().(type) { case SubnetMap[V]: return subnetMap.ToMap() @@ -33,7 +33,7 @@ func RegisterSubnetMapValidation[V any]() { } // 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) { case netip.Addr: if (netipSomething == netip.Addr{}) { diff --git a/common/helpers/validator_test.go b/common/helpers/validator_test.go index 154149f2..d3359fa2 100644 --- a/common/helpers/validator_test.go +++ b/common/helpers/validator_test.go @@ -93,7 +93,7 @@ func TestSubnetMapValidator(t *testing.T) { cases := []struct { Description string - Value interface{} + Value any Error bool }{ { @@ -179,7 +179,7 @@ func TestNetIPValidation(t *testing.T) { } cases := []struct { Description string - Value interface{} + Value any Error bool }{ { diff --git a/common/helpers/yaml/marshal.go b/common/helpers/yaml/marshal.go index 53dfbcd5..69c7b896 100644 --- a/common/helpers/yaml/marshal.go +++ b/common/helpers/yaml/marshal.go @@ -8,6 +8,6 @@ import "gopkg.in/yaml.v3" // Marshal serializes the value provided into a YAML document. The structure of // 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. -func Marshal(in interface{}) (out []byte, err error) { +func Marshal(in any) (out []byte, err error) { return yaml.Marshal(in) } diff --git a/common/helpers/yaml/unmarshal.go b/common/helpers/yaml/unmarshal.go index 6e03b80c..98a8cbac 100644 --- a/common/helpers/yaml/unmarshal.go +++ b/common/helpers/yaml/unmarshal.go @@ -15,14 +15,14 @@ import ( // Unmarshal decodes the first document found within the in byte slice and // 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) } // UnmarshalWithInclude decodes the first document found within the in byte // slice and assigns decoded values into the out value. It also accepts the // "!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 in, err := fs.ReadFile(fsys, input) if err != nil { diff --git a/common/helpers/yaml/unmarshal_test.go b/common/helpers/yaml/unmarshal_test.go index 3b0cea90..49133e1e 100644 --- a/common/helpers/yaml/unmarshal_test.go +++ b/common/helpers/yaml/unmarshal_test.go @@ -15,7 +15,7 @@ import ( func TestUnmarshalWithIn(t *testing.T) { fsys := os.DirFS("testdata") - var got interface{} + var got any if err := yaml.UnmarshalWithInclude(fsys, "base.yaml", &got); err != nil { t.Fatalf("UnmarshalWithInclude() error:\n%+v", err) } @@ -26,7 +26,7 @@ func TestUnmarshalWithIn(t *testing.T) { "file1": gin.H{"name": "1.yaml"}, }, "list1": []string{"el1", "el2", "el3"}, - "list2": []interface{}{gin.H{ + "list2": []any{gin.H{ "protocol": "tcp", "size": 1300, }, "el2", "el3"}, diff --git a/common/httpserver/cache.go b/common/httpserver/cache.go index 0c8b0ec6..7675770f 100644 --- a/common/httpserver/cache.go +++ b/common/httpserver/cache.go @@ -61,6 +61,6 @@ type cacheLogger struct { 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...) } diff --git a/common/httpserver/config.go b/common/httpserver/config.go index 31bee050..dc81f521 100644 --- a/common/httpserver/config.go +++ b/common/httpserver/config.go @@ -104,7 +104,7 @@ func DefaultConfiguration() Configuration { } // MarshalYAML undoes ConfigurationUnmarshallerHook(). -func (cc CacheConfiguration) MarshalYAML() (interface{}, error) { +func (cc CacheConfiguration) MarshalYAML() (any, error) { return helpers.ParametrizedConfigurationMarshalYAML(cc, cacheConfigurationMap) } diff --git a/common/kafka/config.go b/common/kafka/config.go index a6c305b9..c2152ae9 100644 --- a/common/kafka/config.go +++ b/common/kafka/config.go @@ -135,7 +135,7 @@ func NewConfig(r *reporter.Reporter, config Configuration) ([]kgo.Opt, error) { // ConfigurationUnmarshallerHook normalize Kafka configuration: // - move SASL related parameters from TLS section to SASL section 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{})) { return from.Interface(), nil } diff --git a/common/kafka/config_test.go b/common/kafka/config_test.go index 8f0e32f0..707cb5cb 100644 --- a/common/kafka/config_test.go +++ b/common/kafka/config_test.go @@ -93,13 +93,13 @@ func TestTLSConfiguration(t *testing.T) { helpers.TestConfigurationDecode(t, helpers.ConfigurationDecodeCases{ { Description: "no TLS", - Initial: func() interface{} { return DefaultConfiguration() }, - Configuration: func() interface{} { return nil }, + Initial: func() any { return DefaultConfiguration() }, + Configuration: func() any { return nil }, Expected: DefaultConfiguration(), }, { Description: "TLS without auth", - Initial: func() interface{} { return DefaultConfiguration() }, - Configuration: func() interface{} { + Initial: func() any { return DefaultConfiguration() }, + Configuration: func() any { return gin.H{ "tls": gin.H{ "enable": true, @@ -116,8 +116,8 @@ func TestTLSConfiguration(t *testing.T) { }, }, { Description: "TLS SASL plain, skip cert verification (old style)", - Initial: func() interface{} { return DefaultConfiguration() }, - Configuration: func() interface{} { + Initial: func() any { return DefaultConfiguration() }, + Configuration: func() any { return gin.H{ "tls": gin.H{ "enable": true, @@ -143,8 +143,8 @@ func TestTLSConfiguration(t *testing.T) { }, }, { Description: "TLS SASL plain, skip cert verification", - Initial: func() interface{} { return DefaultConfiguration() }, - Configuration: func() interface{} { + Initial: func() any { return DefaultConfiguration() }, + Configuration: func() any { return gin.H{ "sasl": gin.H{ "username": "hello", @@ -168,8 +168,8 @@ func TestTLSConfiguration(t *testing.T) { }, }, { Description: "TLS SASL SCRAM 256", - Initial: func() interface{} { return DefaultConfiguration() }, - Configuration: func() interface{} { + Initial: func() any { return DefaultConfiguration() }, + Configuration: func() any { return gin.H{ "tls": gin.H{ "enable": true, @@ -197,8 +197,8 @@ func TestTLSConfiguration(t *testing.T) { }, }, { Description: "TLS SASL OAuth", - Initial: func() interface{} { return DefaultConfiguration() }, - Configuration: func() interface{} { + Initial: func() any { return DefaultConfiguration() }, + Configuration: func() any { return gin.H{ "tls": gin.H{ "enable": true, @@ -230,8 +230,8 @@ func TestTLSConfiguration(t *testing.T) { }, }, { Description: "OAuth requires a token URL", - Initial: func() interface{} { return DefaultConfiguration() }, - Configuration: func() interface{} { + Initial: func() any { return DefaultConfiguration() }, + Configuration: func() any { return gin.H{ "sasl": gin.H{ "username": "hello", @@ -243,8 +243,8 @@ func TestTLSConfiguration(t *testing.T) { Error: true, }, { Description: "OAuth token URL only with OAuth", - Initial: func() interface{} { return DefaultConfiguration() }, - Configuration: func() interface{} { + Initial: func() any { return DefaultConfiguration() }, + Configuration: func() any { return gin.H{ "sasl": gin.H{ "username": "hello", diff --git a/common/remotedatasource/config_test.go b/common/remotedatasource/config_test.go index 6dcf91f5..8a82903a 100644 --- a/common/remotedatasource/config_test.go +++ b/common/remotedatasource/config_test.go @@ -18,8 +18,8 @@ func TestSourceDecode(t *testing.T) { helpers.TestConfigurationDecode(t, helpers.ConfigurationDecodeCases{ { Description: "Empty", - Initial: func() interface{} { return Source{} }, - Configuration: func() interface{} { + Initial: func() any { return Source{} }, + Configuration: func() any { return gin.H{ "url": "https://example.net", "interval": "10m", @@ -33,8 +33,8 @@ func TestSourceDecode(t *testing.T) { }, }, { Description: "Simple transform", - Initial: func() interface{} { return Source{} }, - Configuration: func() interface{} { + Initial: func() any { return Source{} }, + Configuration: func() any { return gin.H{ "url": "https://example.net", "interval": "10m", @@ -50,8 +50,8 @@ func TestSourceDecode(t *testing.T) { }, }, { Description: "Use POST", - Initial: func() interface{} { return Source{} }, - Configuration: func() interface{} { + Initial: func() any { return Source{} }, + Configuration: func() any { return gin.H{ "url": "https://example.net", "method": "POST", @@ -69,8 +69,8 @@ func TestSourceDecode(t *testing.T) { }, }, { Description: "Complex transform", - Initial: func() interface{} { return Source{} }, - Configuration: func() interface{} { + Initial: func() any { return Source{} }, + Configuration: func() any { return gin.H{ "url": "https://example.net", "interval": "10m", @@ -90,8 +90,8 @@ func TestSourceDecode(t *testing.T) { }, }, { Description: "Incorrect transform", - Initial: func() interface{} { return Source{} }, - Configuration: func() interface{} { + Initial: func() any { return Source{} }, + Configuration: func() any { return gin.H{ "url": "https://example.net", "interval": "10m", diff --git a/common/remotedatasource/root.go b/common/remotedatasource/root.go index 32183973..3a930ed2 100644 --- a/common/remotedatasource/root.go +++ b/common/remotedatasource/root.go @@ -28,7 +28,7 @@ import ( type ProviderFunc func(ctx context.Context, name string, source Source) (int, error) // Component represents a remote data source fetcher. -type Component[T interface{}] struct { +type Component[T any] struct { r *reporter.Reporter t tomb.Tomb provider ProviderFunc @@ -40,7 +40,7 @@ type Component[T interface{}] struct { } // 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]{ r: r, provider: provider, @@ -104,7 +104,7 @@ func (c *Component[T]) Fetch(ctx context.Context, name string, source Source) ([ } reader := bufio.NewReader(resp.Body) decoder := json.NewDecoder(reader) - var got interface{} + var got any if err := decoder.Decode(&got); err != nil { l.Err(err).Msg("cannot decode JSON output") return nil, ErrJSONDecode diff --git a/common/reporter/metrics/logs.go b/common/reporter/metrics/logs.go index adb41e3f..85bde9b3 100644 --- a/common/reporter/metrics/logs.go +++ b/common/reporter/metrics/logs.go @@ -15,7 +15,7 @@ type promHTTPLogger struct { } // Println outputs -func (m promHTTPLogger) Println(v ...interface{}) { +func (m promHTTPLogger) Println(v ...any) { if e := m.l.Debug(); e.Enabled() { e.Msg(fmt.Sprint(v...)) } diff --git a/common/reporter/stack/root.go b/common/reporter/stack/root.go index f0fc477e..bde2ea1d 100644 --- a/common/reporter/stack/root.go +++ b/common/reporter/stack/root.go @@ -21,7 +21,7 @@ type Call uintptr type Trace []Call var pcStackPool = sync.Pool{ - New: func() interface{} { return make([]uintptr, 1000) }, + New: func() any { return make([]uintptr, 1000) }, } func poolBuf() []uintptr { diff --git a/console/authentication/middleware.go b/console/authentication/middleware.go index 3ce1a8a4..2403445f 100644 --- a/console/authentication/middleware.go +++ b/console/authentication/middleware.go @@ -47,7 +47,7 @@ func (customHeaderBinding) Name() string { } // 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() tValue := reflect.TypeOf(obj).Elem() if value.Kind() != reflect.Struct { diff --git a/console/database/logs.go b/console/database/logs.go index 00222aa4..77a89849 100644 --- a/console/database/logs.go +++ b/console/database/logs.go @@ -22,15 +22,15 @@ func (l *logger) LogMode(gormlogger.LogLevel) gormlogger.Interface { 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...) } -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...) } -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...) } diff --git a/console/filter/helpers.go b/console/filter/helpers.go index 3cab1806..0c7dba54 100644 --- a/console/filter/helpers.go +++ b/console/filter/helpers.go @@ -188,18 +188,18 @@ func lastIP(subnet netip.Prefix) netip.Addr { return netip.AddrFrom16(a16) } -func quote(v interface{}) string { +func quote(v any) string { return "'" + strings.NewReplacer(`\`, `\\`, `'`, `\'`).Replace(toString(v)) + "'" } -func toSlice(v interface{}) []interface{} { +func toSlice(v any) []any { if v == nil { return nil } - return v.([]interface{}) + return v.([]any) } -func toString(v interface{}) string { +func toString(v any) string { switch s := v.(type) { case string: return s diff --git a/console/widgets.go b/console/widgets.go index fc22be59..2370b83a 100644 --- a/console/widgets.go +++ b/console/widgets.go @@ -64,7 +64,7 @@ LIMIT 1`, strings.Join(selectClause, ",\n ")) var ( response = gin.H{} columnTypes = rows.ColumnTypes() - vars = make([]interface{}, len(columnTypes)) + vars = make([]any, len(columnTypes)) ) for i := range columnTypes { vars[i] = reflect.New(columnTypes[i].ScanType()).Interface() diff --git a/console/widgets_test.go b/console/widgets_test.go index 77808b23..6259a1d4 100644 --- a/console/widgets_test.go +++ b/console/widgets_test.go @@ -67,7 +67,7 @@ LIMIT 1`). }).AnyTimes() mockRows.EXPECT().Scan(gomock.Any()). - DoAndReturn(func(args ...interface{}) interface{} { + DoAndReturn(func(args ...any) any { arg0 := args[0].(*time.Time) *arg0 = time.Date(2022, 4, 4, 8, 36, 11, 10, time.UTC) arg1 := args[1].(*uint64) diff --git a/demoexporter/snmp/server.go b/demoexporter/snmp/server.go index d487f0e8..cc23c5d2 100644 --- a/demoexporter/snmp/server.go +++ b/demoexporter/snmp/server.go @@ -17,7 +17,7 @@ func (c *Component) newOID(oid string, t gosnmp.Asn1BER, onGet GoSNMPServer.Func return &GoSNMPServer.PDUValueControlItem{ OID: oid, Type: t, - OnGet: func() (interface{}, error) { + OnGet: func() (any, error) { c.metrics.requests.WithLabelValues(oid).Inc() return onGet() }, @@ -28,7 +28,7 @@ func (c *Component) startSNMPServer() error { oids := make([]*GoSNMPServer.PDUValueControlItem, 1+4*len(c.config.Interfaces)) oids[0] = c.newOID("1.3.6.1.2.1.1.5.0", gosnmp.OctetString, - func() (interface{}, error) { + func() (any, error) { return c.config.Name, nil }, ) @@ -38,25 +38,25 @@ func (c *Component) startSNMPServer() error { d := description oids[4*count+1] = c.newOID(fmt.Sprintf("1.3.6.1.2.1.2.2.1.2.%d", i), gosnmp.OctetString, - func() (interface{}, error) { + func() (any, error) { 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), gosnmp.OctetString, - func() (interface{}, error) { + func() (any, error) { 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), gosnmp.Gauge32, - func() (interface{}, error) { + func() (any, error) { 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), gosnmp.OctetString, - func() (interface{}, error) { + func() (any, error) { return d, nil }, ) diff --git a/inlet/flow/config.go b/inlet/flow/config.go index eed0f0ba..de776467 100644 --- a/inlet/flow/config.go +++ b/inlet/flow/config.go @@ -46,7 +46,7 @@ type InputConfiguration struct { } // MarshalYAML undoes ConfigurationUnmarshallerHook(). -func (ic InputConfiguration) MarshalYAML() (interface{}, error) { +func (ic InputConfiguration) MarshalYAML() (any, error) { return helpers.ParametrizedConfigurationMarshalYAML(ic, inputs) } diff --git a/inlet/flow/config_test.go b/inlet/flow/config_test.go index 987f062d..400221db 100644 --- a/inlet/flow/config_test.go +++ b/inlet/flow/config_test.go @@ -21,8 +21,8 @@ func TestDecodeConfiguration(t *testing.T) { helpers.TestConfigurationDecode(t, helpers.ConfigurationDecodeCases{ { Description: "from empty configuration", - Initial: func() interface{} { return Configuration{} }, - Configuration: func() interface{} { + Initial: func() any { return Configuration{} }, + Configuration: func() any { return gin.H{ "inputs": []gin.H{ { @@ -61,7 +61,7 @@ func TestDecodeConfiguration(t *testing.T) { }, }, { Description: "from existing configuration", - Initial: func() interface{} { + Initial: func() any { return Configuration{ Inputs: []InputConfiguration{{ Decoder: pb.RawFlow_DECODER_NETFLOW, @@ -72,7 +72,7 @@ func TestDecodeConfiguration(t *testing.T) { }}, } }, - Configuration: func() interface{} { + Configuration: func() any { return gin.H{ "inputs": []gin.H{ { @@ -108,7 +108,7 @@ func TestDecodeConfiguration(t *testing.T) { }, }, { Description: "change type", - Initial: func() interface{} { + Initial: func() any { return Configuration{ Inputs: []InputConfiguration{{ Decoder: pb.RawFlow_DECODER_NETFLOW, @@ -116,7 +116,7 @@ func TestDecodeConfiguration(t *testing.T) { }}, } }, - Configuration: func() interface{} { + Configuration: func() any { return gin.H{ "inputs": []gin.H{ { @@ -136,7 +136,7 @@ func TestDecodeConfiguration(t *testing.T) { }, }, { Description: "only set one item", - Initial: func() interface{} { + Initial: func() any { return Configuration{ Inputs: []InputConfiguration{{ Decoder: pb.RawFlow_DECODER_NETFLOW, @@ -149,7 +149,7 @@ func TestDecodeConfiguration(t *testing.T) { }}, } }, - Configuration: func() interface{} { + Configuration: func() any { return gin.H{ "inputs": []gin.H{ { @@ -170,10 +170,10 @@ func TestDecodeConfiguration(t *testing.T) { }, }, { Description: "incorrect decoder", - Initial: func() interface{} { + Initial: func() any { return Configuration{} }, - Configuration: func() interface{} { + Configuration: func() any { return gin.H{ "inputs": []gin.H{ { @@ -194,7 +194,7 @@ func TestDecodeConfiguration(t *testing.T) { }, { Description: "netflow timestamp source netflow-packet", - Initial: func() interface{} { + Initial: func() any { return Configuration{ Inputs: []InputConfiguration{{ Decoder: pb.RawFlow_DECODER_NETFLOW, @@ -206,7 +206,7 @@ func TestDecodeConfiguration(t *testing.T) { }}, } }, - Configuration: func() interface{} { + Configuration: func() any { return gin.H{ "inputs": []gin.H{ { @@ -230,7 +230,7 @@ func TestDecodeConfiguration(t *testing.T) { }, { Description: "netflow timestamp source netflow-first-switched", - Initial: func() interface{} { + Initial: func() any { return Configuration{ Inputs: []InputConfiguration{{ Decoder: pb.RawFlow_DECODER_NETFLOW, @@ -242,7 +242,7 @@ func TestDecodeConfiguration(t *testing.T) { }}, } }, - Configuration: func() interface{} { + Configuration: func() any { return gin.H{ "inputs": []gin.H{ { diff --git a/orchestrator/clickhouse/config.go b/orchestrator/clickhouse/config.go index a6151bb2..f9d7828a 100644 --- a/orchestrator/clickhouse/config.go +++ b/orchestrator/clickhouse/config.go @@ -105,7 +105,7 @@ type NetworkAttributes struct { // also accepts a string instead of attributes for backward // compatibility. func NetworkAttributesUnmarshallerHook() mapstructure.DecodeHookFunc { - return func(from, to reflect.Value) (interface{}, error) { + return func(from, to reflect.Value) (any, error) { from = helpers.ElemOrIdentity(from) to = helpers.ElemOrIdentity(to) if to.Type() != reflect.TypeOf(NetworkAttributes{}) { diff --git a/orchestrator/clickhouse/config_test.go b/orchestrator/clickhouse/config_test.go index dcf56199..34ad066b 100644 --- a/orchestrator/clickhouse/config_test.go +++ b/orchestrator/clickhouse/config_test.go @@ -17,46 +17,46 @@ func TestNetworkNamesUnmarshalHook(t *testing.T) { helpers.TestConfigurationDecode(t, helpers.ConfigurationDecodeCases{ { Description: "nil", - Initial: func() interface{} { return helpers.SubnetMap[NetworkAttributes]{} }, - Configuration: func() interface{} { return nil }, + Initial: func() any { return helpers.SubnetMap[NetworkAttributes]{} }, + Configuration: func() any { return nil }, Expected: helpers.SubnetMap[NetworkAttributes]{}, }, { Description: "empty", - Initial: func() interface{} { return helpers.SubnetMap[NetworkAttributes]{} }, - Configuration: func() interface{} { return gin.H{} }, + Initial: func() any { return helpers.SubnetMap[NetworkAttributes]{} }, + Configuration: func() any { return gin.H{} }, Expected: helpers.SubnetMap[NetworkAttributes]{}, }, { Description: "IPv4", - Initial: func() interface{} { return helpers.SubnetMap[NetworkAttributes]{} }, - Configuration: func() interface{} { return gin.H{"203.0.113.0/24": gin.H{"name": "customer"}} }, + Initial: func() any { return helpers.SubnetMap[NetworkAttributes]{} }, + Configuration: func() any { return gin.H{"203.0.113.0/24": gin.H{"name": "customer"}} }, Expected: helpers.MustNewSubnetMap(map[string]NetworkAttributes{ "::ffff:203.0.113.0/120": {Name: "customer"}, }), }, { Description: "IPv6", - Initial: func() interface{} { return helpers.SubnetMap[NetworkAttributes]{} }, - Configuration: func() interface{} { return gin.H{"2001:db8:1::/64": gin.H{"name": "customer"}} }, + Initial: func() any { return helpers.SubnetMap[NetworkAttributes]{} }, + Configuration: func() any { return gin.H{"2001:db8:1::/64": gin.H{"name": "customer"}} }, Expected: helpers.MustNewSubnetMap(map[string]NetworkAttributes{ "2001:db8:1::/64": {Name: "customer"}, }), }, { Description: "IPv4 subnet (compatibility)", - Initial: func() interface{} { return helpers.SubnetMap[NetworkAttributes]{} }, - Configuration: func() interface{} { return gin.H{"203.0.113.0/24": "customer"} }, + Initial: func() any { return helpers.SubnetMap[NetworkAttributes]{} }, + Configuration: func() any { return gin.H{"203.0.113.0/24": "customer"} }, Expected: helpers.MustNewSubnetMap(map[string]NetworkAttributes{ "::ffff:203.0.113.0/120": {Name: "customer"}, }), }, { Description: "IPv6 subnet (compatibility)", - Initial: func() interface{} { return helpers.SubnetMap[NetworkAttributes]{} }, - Configuration: func() interface{} { return gin.H{"2001:db8:1::/64": "customer"} }, + Initial: func() any { return helpers.SubnetMap[NetworkAttributes]{} }, + Configuration: func() any { return gin.H{"2001:db8:1::/64": "customer"} }, Expected: helpers.MustNewSubnetMap(map[string]NetworkAttributes{ "2001:db8:1::/64": {Name: "customer"}, }), }, { Description: "all attributes", - Initial: func() interface{} { return helpers.SubnetMap[NetworkAttributes]{} }, - Configuration: func() interface{} { + Initial: func() any { return helpers.SubnetMap[NetworkAttributes]{} }, + Configuration: func() any { return gin.H{"203.0.113.0/24": gin.H{ "name": "customer1", "role": "customer", @@ -74,13 +74,13 @@ func TestNetworkNamesUnmarshalHook(t *testing.T) { }}), }, { Description: "Invalid subnet (1)", - Initial: func() interface{} { return helpers.SubnetMap[NetworkAttributes]{} }, - Configuration: func() interface{} { return gin.H{"192.0.2.1/38": "customer"} }, + Initial: func() any { return helpers.SubnetMap[NetworkAttributes]{} }, + Configuration: func() any { return gin.H{"192.0.2.1/38": "customer"} }, Error: true, }, { Description: "Invalid subnet (2)", - Initial: func() interface{} { return helpers.SubnetMap[NetworkAttributes]{} }, - Configuration: func() interface{} { return gin.H{"192.0.2.1/255.0.255.0": "customer"} }, + Initial: func() any { return helpers.SubnetMap[NetworkAttributes]{} }, + Configuration: func() any { return gin.H{"192.0.2.1/255.0.255.0": "customer"} }, Error: true, }, }, helpers.DiffFormatter(reflect.TypeOf(helpers.SubnetMap[NetworkAttributes]{}), fmt.Sprint)) diff --git a/orchestrator/clickhouse/migrations.go b/orchestrator/clickhouse/migrations.go index 2a3f302d..77c81c4a 100644 --- a/orchestrator/clickhouse/migrations.go +++ b/orchestrator/clickhouse/migrations.go @@ -19,7 +19,7 @@ type migrationStep struct { // CheckQuery to execute to check if the step is needed. CheckQuery string // Arguments to use for the query - Args []interface{} + Args []any // Function to execute if the query returns no row or returns `0'. Do func() error } diff --git a/orchestrator/geoip/config_test.go b/orchestrator/geoip/config_test.go index acd5346a..dd6bf6bc 100644 --- a/orchestrator/geoip/config_test.go +++ b/orchestrator/geoip/config_test.go @@ -15,18 +15,18 @@ func TestConfigurationUnmarshallerHook(t *testing.T) { helpers.TestConfigurationDecode(t, helpers.ConfigurationDecodeCases{ { Description: "nil", - Initial: func() interface{} { return Configuration{} }, - Configuration: func() interface{} { return nil }, + Initial: func() any { return Configuration{} }, + Configuration: func() any { return nil }, Expected: Configuration{}, }, { Description: "empty", - Initial: func() interface{} { return Configuration{} }, - Configuration: func() interface{} { return gin.H{} }, + Initial: func() any { return Configuration{} }, + Configuration: func() any { return gin.H{} }, Expected: Configuration{}, }, { Description: "no country-database, no geoip-database", - Initial: func() interface{} { return Configuration{} }, - Configuration: func() interface{} { + Initial: func() any { return Configuration{} }, + Configuration: func() any { return gin.H{ "asn-database": []string{"something"}, "optional": true, @@ -38,8 +38,8 @@ func TestConfigurationUnmarshallerHook(t *testing.T) { }, }, { Description: "country-database, no geoip-database", - Initial: func() interface{} { return Configuration{} }, - Configuration: func() interface{} { + Initial: func() any { return Configuration{} }, + Configuration: func() any { return gin.H{ "asn-database": []string{"something"}, "country-database": []string{"something else"}, @@ -51,8 +51,8 @@ func TestConfigurationUnmarshallerHook(t *testing.T) { }, }, { Description: "no country-database, geoip-database", - Initial: func() interface{} { return Configuration{} }, - Configuration: func() interface{} { + Initial: func() any { return Configuration{} }, + Configuration: func() any { return gin.H{ "asn-database": []string{"something"}, "geo-database": []string{"something else"}, @@ -64,8 +64,8 @@ func TestConfigurationUnmarshallerHook(t *testing.T) { }, }, { Description: "both country-database, geoip-database", - Initial: func() interface{} { return Configuration{} }, - Configuration: func() interface{} { + Initial: func() any { return Configuration{} }, + Configuration: func() any { return gin.H{ "asn-database": []string{"something"}, "geo-database": []string{"something else"}, diff --git a/orchestrator/http.go b/orchestrator/http.go index f9b2b552..4078b21f 100644 --- a/orchestrator/http.go +++ b/orchestrator/http.go @@ -20,7 +20,7 @@ func (c *Component) configurationHandlerFunc(gc *gin.Context) { } c.serviceLock.Lock() - var configuration interface{} + var configuration any serviceConfigurations, ok := c.serviceConfigurations[ServiceType(service)] if ok { l := len(serviceConfigurations) diff --git a/orchestrator/root.go b/orchestrator/root.go index 7a6b6cc1..7631d2d8 100644 --- a/orchestrator/root.go +++ b/orchestrator/root.go @@ -18,7 +18,7 @@ type Component struct { config Configuration serviceLock sync.Mutex - serviceConfigurations map[ServiceType][]interface{} + serviceConfigurations map[ServiceType][]any } // Dependencies define the dependencies of the broker. @@ -49,7 +49,7 @@ func New(r *reporter.Reporter, configuration Configuration, dependencies Depende d: &dependencies, config: configuration, - serviceConfigurations: map[ServiceType][]interface{}{}, + serviceConfigurations: map[ServiceType][]any{}, } 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. -func (c *Component) RegisterConfiguration(service ServiceType, configuration interface{}) { +func (c *Component) RegisterConfiguration(service ServiceType, configuration any) { c.serviceLock.Lock() if _, ok := c.serviceConfigurations[service]; !ok { - c.serviceConfigurations[service] = []interface{}{} + c.serviceConfigurations[service] = []any{} } c.serviceConfigurations[service] = append(c.serviceConfigurations[service], configuration) c.serviceLock.Unlock() diff --git a/outlet/core/config.go b/outlet/core/config.go index 172289a4..e5e42ac7 100644 --- a/outlet/core/config.go +++ b/outlet/core/config.go @@ -75,7 +75,7 @@ const ( // ASNProviderUnmarshallerHook normalize a net provider configuration: // - map bmp to routing 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)) { return from.Interface(), nil } @@ -92,7 +92,7 @@ func ASNProviderUnmarshallerHook() mapstructure.DecodeHookFunc { // NetProviderUnmarshallerHook normalize a net provider configuration: // - map bmp to routing 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)) { return from.Interface(), nil } @@ -106,7 +106,7 @@ func NetProviderUnmarshallerHook() mapstructure.DecodeHookFunc { // ConfigurationUnmarshallerHook normalize core configuration: // - replace ignore-asn-from-flow by asn-providers 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{}) { return from.Interface(), nil } diff --git a/outlet/core/config_test.go b/outlet/core/config_test.go index 280b3341..c534bee5 100644 --- a/outlet/core/config_test.go +++ b/outlet/core/config_test.go @@ -21,20 +21,20 @@ func TestConfigurationUnmarshallerHook(t *testing.T) { helpers.TestConfigurationDecode(t, helpers.ConfigurationDecodeCases{ { Description: "nil", - Initial: func() interface{} { return Configuration{} }, - Configuration: func() interface{} { return nil }, + Initial: func() any { return Configuration{} }, + Configuration: func() any { return nil }, Expected: Configuration{}, SkipValidation: true, }, { Description: "empty", - Initial: func() interface{} { return Configuration{} }, - Configuration: func() interface{} { return gin.H{} }, + Initial: func() any { return Configuration{} }, + Configuration: func() any { return gin.H{} }, Expected: Configuration{}, SkipValidation: true, }, { Description: "ignore-asn-from-flow = false", - Initial: func() interface{} { return Configuration{} }, - Configuration: func() interface{} { + Initial: func() any { return Configuration{} }, + Configuration: func() any { return gin.H{ "ignore-asn-from-flow": false, } @@ -43,8 +43,8 @@ func TestConfigurationUnmarshallerHook(t *testing.T) { SkipValidation: true, }, { Description: "ignore-asn-from-flow = true", - Initial: func() interface{} { return Configuration{} }, - Configuration: func() interface{} { + Initial: func() any { return Configuration{} }, + Configuration: func() any { return gin.H{ "ignore-asn-from-flow": true, } @@ -55,8 +55,8 @@ func TestConfigurationUnmarshallerHook(t *testing.T) { SkipValidation: true, }, { Description: "ignore-asn-from-flow and asn-providers", - Initial: func() interface{} { return Configuration{} }, - Configuration: func() interface{} { + Initial: func() any { return Configuration{} }, + Configuration: func() any { return gin.H{ "ignore-asn-from-flow": true, "asn-providers": []string{"routing", "flow"}, @@ -66,8 +66,8 @@ func TestConfigurationUnmarshallerHook(t *testing.T) { SkipValidation: true, }, { Description: "asn-providers only", - Initial: func() interface{} { return Configuration{} }, - Configuration: func() interface{} { + Initial: func() any { return Configuration{} }, + Configuration: func() any { return gin.H{ "asn-providers": []string{"flow-except-private", "routing", "flow"}, } @@ -78,8 +78,8 @@ func TestConfigurationUnmarshallerHook(t *testing.T) { SkipValidation: true, }, { Description: "net-providers with bmp", - Initial: func() interface{} { return Configuration{} }, - Configuration: func() interface{} { + Initial: func() any { return Configuration{} }, + Configuration: func() any { return gin.H{ "net-providers": []string{"flow", "bmp"}, } @@ -90,8 +90,8 @@ func TestConfigurationUnmarshallerHook(t *testing.T) { SkipValidation: true, }, { Description: "asn-providers with bmp", - Initial: func() interface{} { return Configuration{} }, - Configuration: func() interface{} { + Initial: func() any { return Configuration{} }, + Configuration: func() any { return gin.H{ "asn-providers": []string{"flow", "bmp", "bmp-except-private"}, } @@ -102,8 +102,8 @@ func TestConfigurationUnmarshallerHook(t *testing.T) { SkipValidation: true, }, { Description: "net-providers", - Initial: func() interface{} { return Configuration{} }, - Configuration: func() interface{} { + Initial: func() any { return Configuration{} }, + Configuration: func() any { return gin.H{ "net-providers": []string{"flow", "routing"}, } diff --git a/outlet/core/enricher_test.go b/outlet/core/enricher_test.go index 66f2eca5..772bb467 100644 --- a/outlet/core/enricher_test.go +++ b/outlet/core/enricher_test.go @@ -52,7 +52,7 @@ func TestEnrich(t *testing.T) { InIf: 100, OutIf: 200, 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.ColumnInIfName: "Gi0/0/100", schema.ColumnOutIfName: "Gi0/0/200", @@ -82,7 +82,7 @@ func TestEnrich(t *testing.T) { InIf: 100, OutIf: 200, 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.ColumnInIfName: "Gi0/0/100", schema.ColumnOutIfName: "Gi0/0/200", @@ -107,7 +107,7 @@ func TestEnrich(t *testing.T) { InIf: 100, OutIf: 200, 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.ColumnInIfName: "Gi0/0/100", schema.ColumnOutIfName: "Gi0/0/200", @@ -136,7 +136,7 @@ func TestEnrich(t *testing.T) { InIf: 100, OutIf: 200, 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.ColumnInIfName: "Gi0/0/100", schema.ColumnOutIfName: "Gi0/0/200", @@ -168,7 +168,7 @@ func TestEnrich(t *testing.T) { InIf: 100, OutIf: 200, 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.ColumnExporterRegion: "asia", schema.ColumnExporterTenant: "alfred", @@ -202,7 +202,7 @@ func TestEnrich(t *testing.T) { InIf: 100, OutIf: 200, 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.ColumnExporterTenant: "alfred", schema.ColumnInIfName: "Gi0/0/100", @@ -266,7 +266,7 @@ func TestEnrich(t *testing.T) { InIf: 100, OutIf: 200, 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.ColumnInIfProvider: "index1", schema.ColumnOutIfProvider: "index2", @@ -299,7 +299,7 @@ func TestEnrich(t *testing.T) { InIf: 100, OutIf: 200, 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.ColumnInIfName: "eth100", schema.ColumnOutIfName: "Gi0/0/200", @@ -333,7 +333,7 @@ func TestEnrich(t *testing.T) { SrcVlan: 10, DstVlan: 300, 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.ColumnInIfName: "Gi0/0/100", schema.ColumnOutIfName: "Gi0/0/200.300", @@ -368,7 +368,7 @@ ClassifyProviderRegex(Interface.Description, "^Transit: ([^ ]+)", "$1")`, InIf: 100, OutIf: 200, 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.ColumnInIfName: "Gi0/0/100", schema.ColumnOutIfName: "Gi0/0/200", @@ -401,7 +401,7 @@ ClassifyProviderRegex(Interface.Description, "^Transit: ([^ ]+)", "$1")`, InIf: 100, OutIf: 200, 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.ColumnInIfName: "Gi0/0/100", schema.ColumnOutIfName: "Gi0/0/200", @@ -434,7 +434,7 @@ ClassifyProviderRegex(Interface.Description, "^Transit: ([^ ]+)", "$1")`, InIf: 100, OutIf: 200, 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.ColumnInIfName: "Gi0/0/100", schema.ColumnOutIfName: "Gi0/0/200", @@ -468,7 +468,7 @@ ClassifyProviderRegex(Interface.Description, "^Transit: ([^ ]+)", "$1")`, InIf: 100, OutIf: 200, 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.ColumnInIfName: "Gi0/0/100", schema.ColumnOutIfName: "Gi0/0/200", @@ -507,7 +507,7 @@ ClassifyProviderRegex(Interface.Description, "^Transit: ([^ ]+)", "$1")`, InIf: 1010, OutIf: 2010, 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.ColumnExporterGroup: "metadata group", schema.ColumnExporterRegion: "metadata region", @@ -553,7 +553,7 @@ ClassifyProviderRegex(Interface.Description, "^Transit: ([^ ]+)", "$1")`, DstAS: 174, SrcNetMask: 27, DstNetMask: 27, - OtherColumns: map[schema.ColumnKey]interface{}{ + OtherColumns: map[schema.ColumnKey]any{ schema.ColumnExporterName: "192_0_2_142", schema.ColumnInIfName: "Gi0/0/100", schema.ColumnOutIfName: "Gi0/0/200", diff --git a/outlet/core/root_test.go b/outlet/core/root_test.go index ce46f8ea..3c943007 100644 --- a/outlet/core/root_test.go +++ b/outlet/core/root_test.go @@ -82,7 +82,7 @@ func TestCore(t *testing.T) { OutIf: out, SrcAddr: netip.MustParseAddr("::ffff:67.43.156.77"), DstAddr: netip.MustParseAddr("::ffff:2.125.160.216"), - OtherColumns: map[schema.ColumnKey]interface{}{ + OtherColumns: map[schema.ColumnKey]any{ schema.ColumnBytes: 6765, schema.ColumnPackets: 4, schema.ColumnEType: 0x800, diff --git a/outlet/flow/decoder/helpers_test.go b/outlet/flow/decoder/helpers_test.go index 1b57803f..5743f660 100644 --- a/outlet/flow/decoder/helpers_test.go +++ b/outlet/flow/decoder/helpers_test.go @@ -23,7 +23,7 @@ func TestDecodeMPLSAndIPv4(t *testing.T) { expected := schema.FlowMessage{ SrcAddr: netip.MustParseAddr("::ffff:10.31.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.ColumnProto: 6, schema.ColumnSrcPort: 11001, @@ -54,7 +54,7 @@ func TestDecodeVLANAndIPv6(t *testing.T) { SrcVlan: 100, SrcAddr: netip.MustParseAddr("2402:f000:1:8e01::5555"), DstAddr: netip.MustParseAddr("2607:fcd0:100:2300::b108:2a6b"), - OtherColumns: map[schema.ColumnKey]interface{}{ + OtherColumns: map[schema.ColumnKey]any{ schema.ColumnEType: helpers.ETypeIPv6, schema.ColumnProto: 4, schema.ColumnIPTTL: 246, diff --git a/outlet/flow/decoder/netflow/decode.go b/outlet/flow/decoder/netflow/decode.go index dfa64d5f..ba399ef9 100644 --- a/outlet/flow/decoder/netflow/decode.go +++ b/outlet/flow/decoder/netflow/decode.go @@ -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 for _, flowSet := range flowSets { switch tFlowSet := flowSet.(type) { diff --git a/outlet/flow/decoder/netflow/root.go b/outlet/flow/decoder/netflow/root.go index 99bff4af..8242b152 100644 --- a/outlet/flow/decoder/netflow/root.go +++ b/outlet/flow/decoder/netflow/root.go @@ -97,7 +97,7 @@ type templateSystem struct { 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 { return nil } @@ -125,11 +125,11 @@ func (s *templateSystem) AddTemplate(version uint16, obsDomainID uint32, templat 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) } -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) } diff --git a/outlet/metadata/provider/gnmi/config.go b/outlet/metadata/provider/gnmi/config.go index dc67c624..a30c63b4 100644 --- a/outlet/metadata/provider/gnmi/config.go +++ b/outlet/metadata/provider/gnmi/config.go @@ -169,7 +169,7 @@ func DefaultModels() []Model { // ConfigurationUnmarshallerHook normalize gnmi configuration: // - replace an occurrence of "default" in the list of models with the list of default models. 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{}) { return from.Interface(), nil } @@ -192,7 +192,7 @@ func ConfigurationUnmarshallerHook() mapstructure.DecodeHookFunc { val := helpers.ElemOrIdentity(modelsValue.Index(i)) if val.Kind() == reflect.String && val.String() == "defaults" { // 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() { if i != j { newValue = reflect.Append(newValue, modelsValue.Index(j)) diff --git a/outlet/metadata/provider/gnmi/config_test.go b/outlet/metadata/provider/gnmi/config_test.go index 509c7a61..e0d95d72 100644 --- a/outlet/metadata/provider/gnmi/config_test.go +++ b/outlet/metadata/provider/gnmi/config_test.go @@ -22,22 +22,22 @@ func TestDefaults(t *testing.T) { helpers.TestConfigurationDecode(t, helpers.ConfigurationDecodeCases{ { Description: "nil", - Initial: func() interface{} { return Configuration{} }, - Configuration: func() interface{} { return nil }, + Initial: func() any { return Configuration{} }, + Configuration: func() any { return nil }, Expected: Configuration{}, SkipValidation: true, }, { Description: "empty", - Initial: func() interface{} { return Configuration{} }, - Configuration: func() interface{} { return gin.H{} }, + Initial: func() any { return Configuration{} }, + Configuration: func() any { return gin.H{} }, Expected: Configuration{}, SkipValidation: true, }, { Description: "override models", - Initial: func() interface{} { + Initial: func() any { return Configuration{Timeout: time.Second, MinimalRefreshInterval: time.Minute} }, - Configuration: func() interface{} { + Configuration: func() any { return gin.H{ "models": []gin.H{ { @@ -73,10 +73,10 @@ func TestDefaults(t *testing.T) { }, }, { Description: "defaults only", - Initial: func() interface{} { + Initial: func() any { return Configuration{Timeout: time.Second, MinimalRefreshInterval: time.Minute} }, - Configuration: func() interface{} { + Configuration: func() any { return gin.H{ "models": []string{"defaults"}, } @@ -88,12 +88,12 @@ func TestDefaults(t *testing.T) { }, }, { Description: "defaults first", - Initial: func() interface{} { + Initial: func() any { return Configuration{Timeout: time.Second, MinimalRefreshInterval: time.Minute} }, - Configuration: func() interface{} { + Configuration: func() any { return gin.H{ - "models": []interface{}{ + "models": []any{ "defaults", gin.H{ "name": "custom", @@ -126,12 +126,12 @@ func TestDefaults(t *testing.T) { }, }, { Description: "defaults last", - Initial: func() interface{} { + Initial: func() any { return Configuration{Timeout: time.Second, MinimalRefreshInterval: time.Minute} }, - Configuration: func() interface{} { + Configuration: func() any { return gin.H{ - "models": []interface{}{ + "models": []any{ gin.H{ "name": "custom", "if-index-paths": "/some/path", @@ -166,12 +166,12 @@ func TestDefaults(t *testing.T) { }, }, { Description: "defaults in the middle", - Initial: func() interface{} { + Initial: func() any { return Configuration{Timeout: time.Second, MinimalRefreshInterval: time.Minute} }, - Configuration: func() interface{} { + Configuration: func() any { return gin.H{ - "models": []interface{}{ + "models": []any{ gin.H{ "name": "custom1", "if-index-paths": "/some/path", diff --git a/outlet/metadata/provider/gnmi/subscribe.go b/outlet/metadata/provider/gnmi/subscribe.go index 2ff82d85..97909b6a 100644 --- a/outlet/metadata/provider/gnmi/subscribe.go +++ b/outlet/metadata/provider/gnmi/subscribe.go @@ -66,7 +66,7 @@ func subscribeResponseToEvents(response *gnmi.SubscribeResponse) []event { } // For JSON, we need to walk the structure to create events. We // 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 { continue } @@ -91,13 +91,13 @@ func subscribeResponsesToEvents(responses []*gnmi.SubscribeResponse) []event { // jsonAppendToEvents appends the events derived from the provided event plus // 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) { default: return events // Slices: not handled // Maps - case map[string]interface{}: + case map[string]any: for k, v := range value { currentEvent := ev currentEvent.Path = path.Join(currentEvent.Path, k) diff --git a/outlet/metadata/provider/snmp/config.go b/outlet/metadata/provider/snmp/config.go index 5ace9795..d098e017 100644 --- a/outlet/metadata/provider/snmp/config.go +++ b/outlet/metadata/provider/snmp/config.go @@ -66,7 +66,7 @@ func DefaultConfiguration() provider.Configuration { // - convert default-community to credentials (as ::/0) // - merge security parameters and communities into credentials 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{}) { return from.Interface(), nil } diff --git a/outlet/metadata/provider/snmp/config_test.go b/outlet/metadata/provider/snmp/config_test.go index 8d29f33f..7e094a35 100644 --- a/outlet/metadata/provider/snmp/config_test.go +++ b/outlet/metadata/provider/snmp/config_test.go @@ -22,14 +22,14 @@ func TestConfigurationUnmarshallerHook(t *testing.T) { helpers.TestConfigurationDecode(t, helpers.ConfigurationDecodeCases{ { Description: "nil", - Initial: func() interface{} { return Configuration{} }, - Configuration: func() interface{} { return nil }, + Initial: func() any { return Configuration{} }, + Configuration: func() any { return nil }, Expected: Configuration{}, SkipValidation: true, }, { Description: "empty", - Initial: func() interface{} { return Configuration{} }, - Configuration: func() interface{} { return gin.H{} }, + Initial: func() any { return Configuration{} }, + Configuration: func() any { return gin.H{} }, Expected: Configuration{ Credentials: helpers.MustNewSubnetMap(map[string]Credentials{ "::/0": {Communities: []string{"public"}}, @@ -38,8 +38,8 @@ func TestConfigurationUnmarshallerHook(t *testing.T) { SkipValidation: true, }, { Description: "single port", - Initial: func() interface{} { return Configuration{} }, - Configuration: func() interface{} { + Initial: func() any { return Configuration{} }, + Configuration: func() any { return gin.H{ "poller-timeout": "200ms", "ports": "1161", @@ -56,8 +56,8 @@ func TestConfigurationUnmarshallerHook(t *testing.T) { }, }, { Description: "per-prefix port", - Initial: func() interface{} { return Configuration{} }, - Configuration: func() interface{} { + Initial: func() any { return Configuration{} }, + Configuration: func() any { return gin.H{ "poller-timeout": "200ms", "ports": gin.H{ @@ -78,8 +78,8 @@ func TestConfigurationUnmarshallerHook(t *testing.T) { }, }, { Description: "no communities, no default community", - Initial: func() interface{} { return Configuration{} }, - Configuration: func() interface{} { + Initial: func() any { return Configuration{} }, + Configuration: func() any { return gin.H{ "poller-retries": 10, "poller-timeout": "200ms", @@ -94,8 +94,8 @@ func TestConfigurationUnmarshallerHook(t *testing.T) { }, }, { Description: "communities, no default community", - Initial: func() interface{} { return Configuration{} }, - Configuration: func() interface{} { + Initial: func() any { return Configuration{} }, + Configuration: func() any { return gin.H{ "poller-timeout": "200ms", "communities": gin.H{ @@ -114,8 +114,8 @@ func TestConfigurationUnmarshallerHook(t *testing.T) { }, }, { Description: "communities, default community", - Initial: func() interface{} { return Configuration{} }, - Configuration: func() interface{} { + Initial: func() any { return Configuration{} }, + Configuration: func() any { return gin.H{ "poller-timeout": "200ms", "default-community": "private", @@ -135,8 +135,8 @@ func TestConfigurationUnmarshallerHook(t *testing.T) { }, }, { Description: "communities as a string", - Initial: func() interface{} { return Configuration{} }, - Configuration: func() interface{} { + Initial: func() any { return Configuration{} }, + Configuration: func() any { return gin.H{ "poller-timeout": "200ms", "communities": "private", @@ -150,8 +150,8 @@ func TestConfigurationUnmarshallerHook(t *testing.T) { }, }, { Description: "communities, default-community empty", - Initial: func() interface{} { return Configuration{} }, - Configuration: func() interface{} { + Initial: func() any { return Configuration{} }, + Configuration: func() any { return gin.H{ "poller-timeout": "200ms", "default-community": "", @@ -171,8 +171,8 @@ func TestConfigurationUnmarshallerHook(t *testing.T) { }, }, { Description: "SNMP security parameters", - Initial: func() interface{} { return Configuration{} }, - Configuration: func() interface{} { + Initial: func() any { return Configuration{} }, + Configuration: func() any { return gin.H{ "poller-timeout": "200ms", "security-parameters": gin.H{ @@ -198,8 +198,8 @@ func TestConfigurationUnmarshallerHook(t *testing.T) { }, }, { Description: "SNMP security parameters with AES256C", - Initial: func() interface{} { return Configuration{} }, - Configuration: func() interface{} { + Initial: func() any { return Configuration{} }, + Configuration: func() any { return gin.H{ "poller-timeout": "200ms", "security-parameters": gin.H{ @@ -225,8 +225,8 @@ func TestConfigurationUnmarshallerHook(t *testing.T) { }, }, { Description: "SNMP security parameters without privacy protocol", - Initial: func() interface{} { return Configuration{} }, - Configuration: func() interface{} { + Initial: func() any { return Configuration{} }, + Configuration: func() any { return gin.H{ "poller-timeout": "200ms", "security-parameters": gin.H{ @@ -248,8 +248,8 @@ func TestConfigurationUnmarshallerHook(t *testing.T) { }, }, { Description: "SNMP security parameters without authentication protocol", - Initial: func() interface{} { return Configuration{} }, - Configuration: func() interface{} { + Initial: func() any { return Configuration{} }, + Configuration: func() any { return gin.H{ "poller-timeout": "200ms", "security-parameters": gin.H{ @@ -262,8 +262,8 @@ func TestConfigurationUnmarshallerHook(t *testing.T) { Error: true, }, { Description: "SNMP security parameters without authentication passphrase", - Initial: func() interface{} { return Configuration{} }, - Configuration: func() interface{} { + Initial: func() any { return Configuration{} }, + Configuration: func() any { return gin.H{ "poller-timeout": "200ms", "security-parameters": gin.H{ @@ -275,8 +275,8 @@ func TestConfigurationUnmarshallerHook(t *testing.T) { Error: true, }, { Description: "SNMP security parameters without username", - Initial: func() interface{} { return Configuration{} }, - Configuration: func() interface{} { + Initial: func() any { return Configuration{} }, + Configuration: func() any { return gin.H{ "poller-timeout": "200ms", "credentials": gin.H{ @@ -290,8 +290,8 @@ func TestConfigurationUnmarshallerHook(t *testing.T) { Error: true, }, { Description: "merge communities and security-parameters", - Initial: func() interface{} { return Configuration{} }, - Configuration: func() interface{} { + Initial: func() any { return Configuration{} }, + Configuration: func() any { return gin.H{ "poller-timeout": "200ms", "communities": gin.H{ @@ -321,8 +321,8 @@ func TestConfigurationUnmarshallerHook(t *testing.T) { }, }, { Description: "merge communities, security-parameters and credentials", - Initial: func() interface{} { return Configuration{} }, - Configuration: func() interface{} { + Initial: func() any { return Configuration{} }, + Configuration: func() any { return gin.H{ "poller-timeout": "200ms", "communities": gin.H{ @@ -358,8 +358,8 @@ func TestConfigurationUnmarshallerHook(t *testing.T) { }, }, { Description: "merge communities, security-parameters and default credentials", - Initial: func() interface{} { return Configuration{} }, - Configuration: func() interface{} { + Initial: func() any { return Configuration{} }, + Configuration: func() any { return gin.H{ "poller-timeout": "200ms", "communities": gin.H{ @@ -393,8 +393,8 @@ func TestConfigurationUnmarshallerHook(t *testing.T) { }, }, { Description: "conflicting SNMP version", - Initial: func() interface{} { return Configuration{} }, - Configuration: func() interface{} { + Initial: func() any { return Configuration{} }, + Configuration: func() any { return gin.H{ "poller-timeout": "200ms", "credentials": gin.H{ diff --git a/outlet/metadata/provider/snmp/poller.go b/outlet/metadata/provider/snmp/poller.go index 793174f7..a106c80e 100644 --- a/outlet/metadata/provider/snmp/poller.go +++ b/outlet/metadata/provider/snmp/poller.go @@ -215,13 +215,13 @@ type goSNMPLogger struct { r *reporter.Reporter } -func (l *goSNMPLogger) Print(v ...interface{}) { +func (l *goSNMPLogger) Print(v ...any) { if e := l.r.Debug(); e.Enabled() { 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() { e.Msg(fmt.Sprintf(format, v...)) } diff --git a/outlet/metadata/provider/snmp/poller_test.go b/outlet/metadata/provider/snmp/poller_test.go index 666119eb..a0f4a040 100644 --- a/outlet/metadata/provider/snmp/poller_test.go +++ b/outlet/metadata/provider/snmp/poller_test.go @@ -143,91 +143,91 @@ func TestPoller(t *testing.T) { { OID: "1.3.6.1.2.1.1.5.0", Type: gosnmp.OctetString, - OnGet: func() (interface{}, error) { + OnGet: func() (any, error) { return "exporter62", nil }, }, { OID: "1.3.6.1.2.1.2.2.1.2.641", Type: gosnmp.OctetString, - OnGet: func() (interface{}, error) { + OnGet: func() (any, error) { return "Gi0/0/0/0", nil }, }, { OID: "1.3.6.1.2.1.2.2.1.2.642", Type: gosnmp.OctetString, - OnGet: func() (interface{}, error) { + OnGet: func() (any, error) { return "Gi0/0/0/1", nil }, }, { OID: "1.3.6.1.2.1.2.2.1.2.643", Type: gosnmp.OctetString, - OnGet: func() (interface{}, error) { + OnGet: func() (any, error) { return "Gi0/0/0/2", nil }, }, { OID: "1.3.6.1.2.1.2.2.1.2.645", Type: gosnmp.OctetString, - OnGet: func() (interface{}, error) { + OnGet: func() (any, error) { return "Correct description", nil }, }, { OID: "1.3.6.1.2.1.31.1.1.1.1.641", Type: gosnmp.OctetString, - OnGet: func() (interface{}, error) { + OnGet: func() (any, error) { return "Gi0/0/0/0", nil }, }, { OID: "1.3.6.1.2.1.31.1.1.1.1.642", Type: gosnmp.OctetString, - OnGet: func() (interface{}, error) { + OnGet: func() (any, error) { return "Gi0/0/0/1", nil }, }, { OID: "1.3.6.1.2.1.31.1.1.1.1.643", Type: gosnmp.OctetString, - OnGet: func() (interface{}, error) { + OnGet: func() (any, error) { return "Gi0/0/0/2", nil }, }, { OID: "1.3.6.1.2.1.31.1.1.1.1.645", Type: gosnmp.OctetString, - OnGet: func() (interface{}, error) { + OnGet: func() (any, error) { return "Gi0/0/0/5", nil }, }, { OID: "1.3.6.1.2.1.31.1.1.1.15.641", Type: gosnmp.Gauge32, - OnGet: func() (interface{}, error) { + OnGet: func() (any, error) { return uint(10000), nil }, }, { OID: "1.3.6.1.2.1.31.1.1.1.15.642", Type: gosnmp.Gauge32, - OnGet: func() (interface{}, error) { + OnGet: func() (any, error) { return uint(20000), nil }, }, { OID: "1.3.6.1.2.1.31.1.1.1.15.643", Type: gosnmp.Gauge32, - OnGet: func() (interface{}, error) { + OnGet: func() (any, error) { return uint(10000), nil }, }, { OID: "1.3.6.1.2.1.31.1.1.1.15.645", Type: gosnmp.Gauge32, - OnGet: func() (interface{}, error) { + OnGet: func() (any, error) { return uint(1000), nil }, }, { OID: "1.3.6.1.2.1.31.1.1.1.18.641", Type: gosnmp.OctetString, - OnGet: func() (interface{}, error) { + OnGet: func() (any, error) { return "Transit", nil }, }, { OID: "1.3.6.1.2.1.31.1.1.1.18.642", Type: gosnmp.OctetString, - OnGet: func() (interface{}, error) { + OnGet: func() (any, error) { 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", Type: gosnmp.OctetString, - OnGet: func() (interface{}, error) { + OnGet: func() (any, error) { return "Gi0/0/0/5", nil }, }, diff --git a/outlet/routing/config.go b/outlet/routing/config.go index 4bad69c3..bee59873 100644 --- a/outlet/routing/config.go +++ b/outlet/routing/config.go @@ -28,7 +28,7 @@ type ProviderConfiguration struct { } // MarshalYAML undoes ConfigurationUnmarshallerHook(). -func (pc ProviderConfiguration) MarshalYAML() (interface{}, error) { +func (pc ProviderConfiguration) MarshalYAML() (any, error) { return helpers.ParametrizedConfigurationMarshalYAML(pc, providers) }