Skip to content

Commit e8596c5

Browse files
authored
Refactor interface{} to any (#614)
1 parent 041dc62 commit e8596c5

28 files changed

+156
-156
lines changed

act/registry.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ func runActionWithTimeout(
376376
if !action.Sync {
377377
execMode = "async"
378378
}
379-
logger.Debug().Fields(map[string]interface{}{
379+
logger.Debug().Fields(map[string]any{
380380
"executionMode": execMode,
381381
"action": action.Name,
382382
}).Msgf("Running action")

act/registry_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ func Test_Apply_ContradictorySignals(t *testing.T) {
309309
t, buf.String(), "Terminal signal takes precedence, ignoring non-terminal signals")
310310
assert.Equal(t, "log", outputs[1].MatchedPolicy)
311311
assert.Equal(t,
312-
map[string]interface{}{
312+
map[string]any{
313313
"async": true,
314314
"level": "info",
315315
"log": true,
@@ -646,7 +646,7 @@ func Test_Run_Terminate(t *testing.T) {
646646
})
647647
assert.NotNil(t, outputs)
648648
assert.Equal(t, "terminate", outputs[0].MatchedPolicy)
649-
assert.Equal(t, outputs[0].Metadata, map[string]interface{}{"terminate": true})
649+
assert.Equal(t, outputs[0].Metadata, map[string]any{"terminate": true})
650650
assert.True(t, outputs[0].Sync)
651651
assert.True(t, cast.ToBool(outputs[0].Verdict))
652652
assert.True(t, outputs[0].Terminal)
@@ -685,7 +685,7 @@ func Test_Run_Async(t *testing.T) {
685685
assert.NotNil(t, outputs)
686686
assert.Equal(t, "log", outputs[0].MatchedPolicy)
687687
assert.Equal(t,
688-
map[string]interface{}{
688+
map[string]any{
689689
"async": true,
690690
"level": "info",
691691
"log": true,
@@ -764,7 +764,7 @@ func Test_Run_Async_Redis(t *testing.T) {
764764
assert.NotNil(t, outputs)
765765
assert.Equal(t, "log", outputs[0].MatchedPolicy)
766766
assert.Equal(t,
767-
map[string]interface{}{
767+
map[string]any{
768768
"async": true,
769769
"level": "info",
770770
"log": true,
@@ -900,7 +900,7 @@ func Test_Run_Timeout(t *testing.T) {
900900
assert.NotNil(t, outputs)
901901
assert.Equal(t, name, outputs[0].MatchedPolicy)
902902
assert.Equal(t,
903-
map[string]interface{}{
903+
map[string]any{
904904
"async": isAsync,
905905
"level": "info",
906906
"log": true,

api/api.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ func (a *API) GetGlobalConfig(_ context.Context, group *v1.Group) (*structpb.Str
6464

6565
var (
6666
jsonData []byte
67-
global map[string]interface{}
67+
global map[string]any
6868
err error
6969
)
7070

api/api_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ func TestGetGlobalConfigWithGroupName(t *testing.T) {
8181
assert.NotEmpty(t, globalconf["servers"])
8282
assert.NotEmpty(t, globalconf["metrics"])
8383
assert.NotEmpty(t, globalconf["api"])
84-
if _, ok := globalconf["loggers"].(map[string]interface{})[config.Default]; !ok {
84+
if _, ok := globalconf["loggers"].(map[string]any)[config.Default]; !ok {
8585
t.Errorf("loggers.default is not found")
8686
}
8787
}
@@ -374,7 +374,7 @@ func TestGetServers(t *testing.T) {
374374
assert.NotEmpty(t, servers)
375375
assert.NotEmpty(t, servers.AsMap())
376376

377-
if defaultServer, ok := servers.AsMap()[config.Default].(map[string]interface{}); ok {
377+
if defaultServer, ok := servers.AsMap()[config.Default].(map[string]any); ok {
378378
assert.Equal(t, config.DefaultNetwork, defaultServer["network"])
379379
statusFloat, isStatusFloat := defaultServer["status"].(float64)
380380
assert.True(t, isStatusFloat, "status should be of type float64")
@@ -383,7 +383,7 @@ func TestGetServers(t *testing.T) {
383383
tickIntervalFloat, isTickIntervalFloat := defaultServer["tickInterval"].(float64)
384384
assert.True(t, isTickIntervalFloat, "tickInterval should be of type float64")
385385
assert.Equal(t, config.DefaultTickInterval.Nanoseconds(), int64(tickIntervalFloat))
386-
loadBalancerMap, isLoadBalancerMap := defaultServer["loadBalancer"].(map[string]interface{})
386+
loadBalancerMap, isLoadBalancerMap := defaultServer["loadBalancer"].(map[string]any)
387387
assert.True(t, isLoadBalancerMap, "loadBalancer should be a map")
388388
assert.Equal(t, config.DefaultLoadBalancerStrategy, loadBalancerMap["strategy"])
389389
} else {

api/http_server_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func Test_HTTP_Server(t *testing.T) {
4646
defer resp.Body.Close()
4747
assert.Equal(t, http.StatusOK, resp.StatusCode)
4848
assert.Equal(t, "application/json", resp.Header.Get("Content-Type"))
49-
var respBody map[string]interface{}
49+
var respBody map[string]any
5050
err = json.NewDecoder(resp.Body).Decode(&respBody)
5151
require.NoError(t, err)
5252
assert.Equal(t, config.Version, respBody["version"])

cmd/configs.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ func lintConfig(fileType configFileType, configFile string) *gerr.GatewayDError
117117
}
118118

119119
// Unmarshal the JSON data into a map.
120-
var jsonBytes map[string]interface{}
120+
var jsonBytes map[string]any
121121
err = json.Unmarshal(jsonData, &jsonBytes)
122122
if err != nil {
123123
return gerr.ErrLintingFailed.Wrap(err)

cmd/plugin_install.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ var pluginInstallCmd = &cobra.Command{
109109
}
110110

111111
// Get the registered plugins from the plugins configuration file.
112-
var localPluginsConfig map[string]interface{}
112+
var localPluginsConfig map[string]any
113113
if err := yamlv3.Unmarshal(pluginsConfig, &localPluginsConfig); err != nil {
114114
cmd.Println("Failed to unmarshal the plugins configuration file: ", err)
115115
return
@@ -756,7 +756,7 @@ func installPlugin(cmd *cobra.Command, pluginURL string) {
756756
}
757757

758758
// Get the registered plugins from the plugins configuration file.
759-
var localPluginsConfig map[string]interface{}
759+
var localPluginsConfig map[string]any
760760
if err := yamlv3.Unmarshal(pluginsConfig, &localPluginsConfig); err != nil {
761761
cmd.Println("Failed to unmarshal the plugins configuration file: ", err)
762762
return
@@ -881,7 +881,7 @@ func installPlugin(cmd *cobra.Command, pluginURL string) {
881881
}
882882

883883
// Get the plugin configuration from the downloaded plugins configuration file.
884-
var downloadedPluginConfig map[string]interface{}
884+
var downloadedPluginConfig map[string]any
885885
if err := yamlv3.Unmarshal([]byte(contents), &downloadedPluginConfig); err != nil {
886886
cmd.Println("Failed to unmarshal the downloaded plugins configuration file: ", err)
887887
return

cmd/plugin_scaffold_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func Test_pluginScaffoldCmd(t *testing.T) {
4949
pluginsConfig, err := os.ReadFile(filepath.Join(pluginDir, "gatewayd_plugin.yaml"))
5050
require.NoError(t, err, "reading plugins config file should not return an error")
5151

52-
var localPluginsConfig map[string]interface{}
52+
var localPluginsConfig map[string]any
5353
err = yamlv3.Unmarshal(pluginsConfig, &localPluginsConfig)
5454
require.NoError(t, err, "unmarshalling yaml file should not return error")
5555

@@ -71,7 +71,7 @@ func Test_pluginScaffoldCmd(t *testing.T) {
7171
plugin["checksum"] = sum
7272

7373
pluginsList[0] = plugin
74-
plugins := make(map[string]interface{})
74+
plugins := make(map[string]any)
7575
plugins["plugins"] = pluginsList
7676

7777
updatedPluginConfig, err := yamlv3.Marshal(plugins)

cmd/run.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ func StopGracefully(
111111
//nolint:contextcheck
112112
_, err := pluginRegistry.Run(
113113
pluginTimeoutCtx,
114-
map[string]interface{}{"signal": currentSignal},
114+
map[string]any{"signal": currentSignal},
115115
v1.HookName_HOOK_NAME_ON_SIGNAL,
116116
)
117117
if err != nil {
@@ -332,7 +332,7 @@ var runCmd = &cobra.Command{
332332
}
333333
}
334334

335-
logger.Info().Fields(map[string]interface{}{
335+
logger.Info().Fields(map[string]any{
336336
"policies": maps.Keys(actRegistry.Policies),
337337
}).Msg("Policies are loaded")
338338

@@ -561,7 +561,7 @@ var runCmd = &cobra.Command{
561561
IdleTimeout: timeout,
562562
}
563563

564-
logger.Info().Fields(map[string]interface{}{
564+
logger.Info().Fields(map[string]any{
565565
"address": address,
566566
"timeout": timeout.String(),
567567
"readHeaderTimeout": readHeaderTimeout.String(),
@@ -605,7 +605,7 @@ var runCmd = &cobra.Command{
605605
pluginTimeoutCtx, cancel = context.WithTimeout(context.Background(), conf.Plugin.Timeout)
606606
defer cancel()
607607

608-
if data, ok := conf.GlobalKoanf.Get("loggers").(map[string]interface{}); ok {
608+
if data, ok := conf.GlobalKoanf.Get("loggers").(map[string]any); ok {
609609
_, err = pluginRegistry.Run(
610610
pluginTimeoutCtx, data, v1.HookName_HOOK_NAME_ON_NEW_LOGGER)
611611
if err != nil {
@@ -747,7 +747,7 @@ var runCmd = &cobra.Command{
747747
context.Background(), conf.Plugin.Timeout)
748748
defer cancel()
749749

750-
clientCfg := map[string]interface{}{
750+
clientCfg := map[string]any{
751751
"id": client.ID,
752752
"name": configBlockName,
753753
"group": configGroupName,
@@ -804,7 +804,7 @@ var runCmd = &cobra.Command{
804804
}
805805

806806
// Verify that the pool is properly populated.
807-
logger.Info().Fields(map[string]interface{}{
807+
logger.Info().Fields(map[string]any{
808808
"name": configBlockName,
809809
"count": strconv.Itoa(pools[configGroupName][configBlockName].Size()),
810810
}).Msg("There are clients available in the pool")
@@ -824,7 +824,7 @@ var runCmd = &cobra.Command{
824824

825825
_, err = pluginRegistry.Run(
826826
pluginTimeoutCtx,
827-
map[string]interface{}{"name": configBlockName, "size": currentPoolSize},
827+
map[string]any{"name": configBlockName, "size": currentPoolSize},
828828
v1.HookName_HOOK_NAME_ON_NEW_POOL)
829829
if err != nil {
830830
logger.Error().Err(err).Msg("Failed to run OnNewPool hooks")
@@ -876,7 +876,7 @@ var runCmd = &cobra.Command{
876876
context.Background(), conf.Plugin.Timeout)
877877
defer cancel()
878878

879-
if data, ok := conf.GlobalKoanf.Get("proxies").(map[string]interface{}); ok {
879+
if data, ok := conf.GlobalKoanf.Get("proxies").(map[string]any); ok {
880880
_, err = pluginRegistry.Run(
881881
pluginTimeoutCtx, data, v1.HookName_HOOK_NAME_ON_NEW_PROXY)
882882
if err != nil {
@@ -947,7 +947,7 @@ var runCmd = &cobra.Command{
947947
context.Background(), conf.Plugin.Timeout)
948948
defer cancel()
949949

950-
if data, ok := conf.GlobalKoanf.Get("servers").(map[string]interface{}); ok {
950+
if data, ok := conf.GlobalKoanf.Get("servers").(map[string]any); ok {
951951
_, err = pluginRegistry.Run(
952952
pluginTimeoutCtx, data, v1.HookName_HOOK_NAME_ON_NEW_SERVER)
953953
if err != nil {
@@ -994,7 +994,7 @@ var runCmd = &cobra.Command{
994994
go httpServer.Start()
995995

996996
logger.Info().Fields(
997-
map[string]interface{}{
997+
map[string]any{
998998
"network": apiOptions.GRPCNetwork,
999999
"address": apiOptions.GRPCAddress,
10001000
},

config/config.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ type IConfig interface {
3232
LoadGlobalConfigFile(ctx context.Context) *gerr.GatewayDError
3333
LoadPluginConfigFile(ctx context.Context) *gerr.GatewayDError
3434
MergeGlobalConfig(
35-
ctx context.Context, updatedGlobalConfig map[string]interface{}) *gerr.GatewayDError
35+
ctx context.Context, updatedGlobalConfig map[string]any) *gerr.GatewayDError
3636
}
3737

3838
type Config struct {
@@ -344,7 +344,7 @@ func loadEnvVars() *env.Env {
344344

345345
// transformEnvVariable transforms the environment variable name to a format based on JSON tags.
346346
func transformEnvVariable(envVar string) string {
347-
structs := []interface{}{
347+
structs := []any{
348348
&API{},
349349
&Logger{},
350350
&Pool{},
@@ -444,7 +444,7 @@ func (c *Config) UnmarshalPluginConfig(ctx context.Context) *gerr.GatewayDError
444444
}
445445

446446
func (c *Config) MergeGlobalConfig(
447-
ctx context.Context, updatedGlobalConfig map[string]interface{},
447+
ctx context.Context, updatedGlobalConfig map[string]any,
448448
) *gerr.GatewayDError {
449449
_, span := otel.Tracer(TracerName).Start(ctx, "Merge global config from plugins")
450450

@@ -530,7 +530,7 @@ func (c *Config) ConvertKeysToLowercase(ctx context.Context) *gerr.GatewayDError
530530
globalConfig.Servers = convertMapKeysToLowercase(globalConfig.Servers)
531531
globalConfig.Metrics = convertMapKeysToLowercase(globalConfig.Metrics)
532532

533-
// Convert the globalConfig back to a map[string]interface{}
533+
// Convert the globalConfig back to a map[string]any
534534
configMap, err := structToMap(globalConfig)
535535
if err != nil {
536536
span.RecordError(err)
@@ -554,9 +554,9 @@ func (c *Config) ConvertKeysToLowercase(ctx context.Context) *gerr.GatewayDError
554554
return nil
555555
}
556556

557-
// structToMap converts a given struct to a map[string]interface{}.
558-
func structToMap(v interface{}) (map[string]interface{}, error) {
559-
var result map[string]interface{}
557+
// structToMap converts a given struct to a map[string]any.
558+
func structToMap(v any) (map[string]any, error) {
559+
var result map[string]any
560560
data, err := json.Marshal(v)
561561
if err != nil {
562562
return nil, fmt.Errorf("failed to marshal struct: %w", err)
@@ -785,7 +785,7 @@ func (c *Config) ValidateGlobalConfig(ctx context.Context) *gerr.GatewayDError {
785785
}
786786

787787
// generateTagMapping generates a map of JSON tags to lower case json tags.
788-
func generateTagMapping(structs []interface{}, tagMapping map[string]string) {
788+
func generateTagMapping(structs []any, tagMapping map[string]string) {
789789
for _, s := range structs {
790790
structValue := reflect.ValueOf(s).Elem()
791791
structType := structValue.Type()
@@ -796,7 +796,7 @@ func generateTagMapping(structs []interface{}, tagMapping map[string]string) {
796796

797797
// Handle nested structs
798798
if field.Type.Kind() == reflect.Struct {
799-
generateTagMapping([]interface{}{fieldValue.Addr().Interface()}, tagMapping)
799+
generateTagMapping([]any{fieldValue.Addr().Interface()}, tagMapping)
800800
}
801801

802802
jsonTag := field.Tag.Get("json")

0 commit comments

Comments
 (0)