From 06f7b082f224f393cfbe8dd3408a85e9c402b6f5 Mon Sep 17 00:00:00 2001 From: Mostafa Moradian Date: Sun, 5 Mar 2023 13:25:52 +0100 Subject: [PATCH] Fix some linter errors and ignore others --- .golangci.yaml | 1 + api/api.go | 52 +++++++++++++++++++++++----------------------- api/http_server.go | 2 +- 3 files changed, 28 insertions(+), 27 deletions(-) diff --git a/.golangci.yaml b/.golangci.yaml index 55046dad..cc2aac6d 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -17,3 +17,4 @@ linters: - maligned - funlen - maintidx + - musttag diff --git a/api/api.go b/api/api.go index 6a9267fe..1fddfbf1 100644 --- a/api/api.go +++ b/api/api.go @@ -77,29 +77,29 @@ func (a *API) GetPluginConfig(ctx context.Context, _ *emptypb.Empty) (*structpb. func (a *API) GetPlugins(context.Context, *emptypb.Empty) (*v1.PluginConfigs, error) { plugins := make([]*v1.PluginConfig, 0) a.PluginRegistry.ForEach( - func(id sdkPlugin.Identifier, p *plugin.Plugin) { + func(pluginID sdkPlugin.Identifier, plugIn *plugin.Plugin) { requires := make(map[string]string, 0) - if p.Requires != nil { - for _, r := range p.Requires { + if plugIn.Requires != nil { + for _, r := range plugIn.Requires { requires[r.Name] = r.Version } } plugins = append(plugins, &v1.PluginConfig{ Id: &v1.PluginID{ - Name: id.Name, - Version: id.Version, - RemoteUrl: id.RemoteURL, - Checksum: id.Checksum, + Name: pluginID.Name, + Version: pluginID.Version, + RemoteUrl: pluginID.RemoteURL, + Checksum: pluginID.Checksum, }, - Description: p.Description, - Authors: p.Authors, - License: p.License, - ProjectUrl: p.ProjectURL, - Config: p.Config, - Hooks: p.Hooks, + Description: plugIn.Description, + Authors: plugIn.Authors, + License: plugIn.License, + ProjectUrl: plugIn.ProjectURL, + Config: plugIn.Config, + Hooks: plugIn.Hooks, Requires: requires, - Tags: p.Tags, - Categories: p.Categories, + Tags: plugIn.Tags, + Categories: plugIn.Categories, }) }, ) @@ -127,15 +127,15 @@ func (a *API) GetPools(ctx context.Context, _ *emptypb.Empty) (*structpb.Struct, // GetProxies returns the proxy configuration of the GatewayD. func (a *API) GetProxies(ctx context.Context, _ *emptypb.Empty) (*structpb.Struct, error) { proxies := make(map[string]interface{}, 0) - for name, p := range a.Proxies { + for name, proxy := range a.Proxies { available := make([]interface{}, 0) - for _, c := range p.AvailableConnections() { + for _, c := range proxy.AvailableConnections() { available = append(available, c) } busy := make([]interface{}, 0) - for _, c := range p.BusyConnections() { - busy = append(busy, c) + for _, conn := range proxy.BusyConnections() { + busy = append(busy, conn) } proxies[name] = map[string]interface{}{ @@ -154,14 +154,14 @@ func (a *API) GetProxies(ctx context.Context, _ *emptypb.Empty) (*structpb.Struc // GetServers returns the server configuration of the GatewayD. func (a *API) GetServers(ctx context.Context, _ *emptypb.Empty) (*structpb.Struct, error) { servers := make(map[string]interface{}, 0) - for name, s := range a.Servers { + for name, server := range a.Servers { servers[name] = map[string]interface{}{ - "network": s.Network, - "address": s.Address, - "status": uint(s.Status), - "softLimit": s.SoftLimit, - "hardLimit": s.HardLimit, - "tickInterval": s.TickInterval.Nanoseconds(), + "network": server.Network, + "address": server.Address, + "status": uint(server.Status), + "softLimit": server.SoftLimit, + "hardLimit": server.HardLimit, + "tickInterval": server.TickInterval.Nanoseconds(), } } serversConfig, err := structpb.NewStruct(servers) diff --git a/api/http_server.go b/api/http_server.go index 0c954f96..3f3c23fa 100644 --- a/api/http_server.go +++ b/api/http_server.go @@ -61,7 +61,7 @@ func StartHTTPAPI(options *Options) { } // Start HTTP server (and proxy calls to gRPC server endpoint) - if err := http.ListenAndServe(options.HTTPAddress, mux); err != nil { + if err := http.ListenAndServe(options.HTTPAddress, mux); err != nil { //nolint:gosec options.Logger.Err(err).Msg("failed to start HTTP API") } }