From 77fa22f7365c5bbb3c1f59ba987bb92eb33593a2 Mon Sep 17 00:00:00 2001 From: Andy Dunstall Date: Mon, 24 Jun 2024 06:25:18 +0100 Subject: [PATCH 1/2] ci: update linter version --- .github/workflows/build.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 5899d2e..bcec485 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -54,4 +54,4 @@ jobs: - name: golangci-lint uses: golangci/golangci-lint-action@v3 with: - version: v1.54.1 + version: v1.59.1 From 889a826d58b5e466128539edf055e14217c35729 Mon Sep 17 00:00:00 2001 From: Andy Dunstall Date: Mon, 24 Jun 2024 06:36:04 +0100 Subject: [PATCH 2/2] lint: fix linter rules Fixes linter rules after updating to v1.59.1. --- agent/client/client_test.go | 1 + agent/reverseproxy/reverseproxy_test.go | 2 +- cli/agent/command.go | 2 +- cli/agent/http.go | 4 ++-- cli/agent/start.go | 4 ++-- cli/agent/tcp.go | 4 ++-- cli/forward/command.go | 2 +- cli/forward/start.go | 4 ++-- cli/forward/tcp.go | 4 ++-- cli/server/command.go | 4 ++-- cli/server/status/cluster.go | 4 ++-- cli/server/status/command.go | 2 +- cli/server/status/gossip.go | 4 ++-- cli/server/status/upstream.go | 2 +- cli/workload/requests.go | 2 +- cli/workload/upstreams.go | 2 +- pkg/log/logger.go | 2 +- server/proxy/httpproxy_test.go | 9 ++++++++- server/proxy/tcpproxy_test.go | 4 ++++ tests/cluster_test.go | 6 +++--- 20 files changed, 40 insertions(+), 28 deletions(-) diff --git a/agent/client/client_test.go b/agent/client/client_test.go index 69c3794..23d9716 100644 --- a/agent/client/client_test.go +++ b/agent/client/client_test.go @@ -9,6 +9,7 @@ import ( ) func handler(w http.ResponseWriter, _ *http.Request) { + // nolint fmt.Fprintln(w, "Hello from Piko") } diff --git a/agent/reverseproxy/reverseproxy_test.go b/agent/reverseproxy/reverseproxy_test.go index ad56e2e..bd07c34 100644 --- a/agent/reverseproxy/reverseproxy_test.go +++ b/agent/reverseproxy/reverseproxy_test.go @@ -58,7 +58,7 @@ func TestReverseProxy_Forward(t *testing.T) { t.Run("timeout", func(t *testing.T) { blockCh := make(chan struct{}) upstream := httptest.NewServer(http.HandlerFunc( - func(w http.ResponseWriter, r *http.Request) { + func(_ http.ResponseWriter, _ *http.Request) { <-blockCh }, )) diff --git a/cli/agent/command.go b/cli/agent/command.go index e4f75fc..738ee52 100644 --- a/cli/agent/command.go +++ b/cli/agent/command.go @@ -68,7 +68,7 @@ Examples: conf.RegisterFlags(cmd.PersistentFlags()) loadConf.RegisterFlags(cmd.PersistentFlags()) - cmd.PersistentPreRun = func(cmd *cobra.Command, args []string) { + cmd.PersistentPreRun = func(_ *cobra.Command, _ []string) { if err := loadConf.Load(&conf); err != nil { fmt.Println(err.Error()) os.Exit(1) diff --git a/cli/agent/http.go b/cli/agent/http.go index b67a5cf..b8da1ff 100644 --- a/cli/agent/http.go +++ b/cli/agent/http.go @@ -54,7 +54,7 @@ Timeout forwarding incoming HTTP requests to the upstream.`, var logger log.Logger - cmd.PreRun = func(cmd *cobra.Command, args []string) { + cmd.PreRun = func(_ *cobra.Command, args []string) { // Discard any listeners in the configuration file and use from command // line. conf.Listeners = []config.ListenerConfig{{ @@ -73,7 +73,7 @@ Timeout forwarding incoming HTTP requests to the upstream.`, } } - cmd.Run = func(cmd *cobra.Command, args []string) { + cmd.Run = func(_ *cobra.Command, _ []string) { if err := runAgent(conf, logger); err != nil { logger.Error("failed to run agent", zap.Error(err)) os.Exit(1) diff --git a/cli/agent/start.go b/cli/agent/start.go index 5bd9830..cb5c8c4 100644 --- a/cli/agent/start.go +++ b/cli/agent/start.go @@ -25,7 +25,7 @@ Examples: var logger log.Logger - cmd.PreRun = func(cmd *cobra.Command, args []string) { + cmd.PreRun = func(_ *cobra.Command, _ []string) { var err error logger, err = log.NewLogger(conf.Log.Level, conf.Log.Subsystems) if err != nil { @@ -39,7 +39,7 @@ Examples: } } - cmd.Run = func(cmd *cobra.Command, args []string) { + cmd.Run = func(_ *cobra.Command, _ []string) { if err := runAgent(conf, logger); err != nil { logger.Error("failed to run agent", zap.Error(err)) os.Exit(1) diff --git a/cli/agent/tcp.go b/cli/agent/tcp.go index 8c54c1e..5173e4e 100644 --- a/cli/agent/tcp.go +++ b/cli/agent/tcp.go @@ -51,7 +51,7 @@ Timeout connecting to the upstream.`, var logger log.Logger - cmd.PreRun = func(cmd *cobra.Command, args []string) { + cmd.PreRun = func(_ *cobra.Command, args []string) { // Discard any listeners in the configuration file and use from command // line. conf.Listeners = []config.ListenerConfig{{ @@ -70,7 +70,7 @@ Timeout connecting to the upstream.`, } } - cmd.Run = func(cmd *cobra.Command, args []string) { + cmd.Run = func(_ *cobra.Command, _ []string) { if err := runAgent(conf, logger); err != nil { logger.Error("failed to run agent", zap.Error(err)) os.Exit(1) diff --git a/cli/forward/command.go b/cli/forward/command.go index 13b2e9e..ff3f122 100644 --- a/cli/forward/command.go +++ b/cli/forward/command.go @@ -49,7 +49,7 @@ Examples: conf.RegisterFlags(cmd.PersistentFlags()) loadConf.RegisterFlags(cmd.PersistentFlags()) - cmd.PersistentPreRun = func(cmd *cobra.Command, args []string) { + cmd.PersistentPreRun = func(_ *cobra.Command, _ []string) { if err := loadConf.Load(&conf); err != nil { fmt.Println(err.Error()) os.Exit(1) diff --git a/cli/forward/start.go b/cli/forward/start.go index 18215fa..b34a331 100644 --- a/cli/forward/start.go +++ b/cli/forward/start.go @@ -25,7 +25,7 @@ Examples: var logger log.Logger - cmd.PreRun = func(cmd *cobra.Command, args []string) { + cmd.PreRun = func(_ *cobra.Command, _ []string) { var err error logger, err = log.NewLogger(conf.Log.Level, conf.Log.Subsystems) if err != nil { @@ -39,7 +39,7 @@ Examples: } } - cmd.Run = func(cmd *cobra.Command, args []string) { + cmd.Run = func(_ *cobra.Command, _ []string) { if err := runForward(conf, logger); err != nil { logger.Error("failed to run forward", zap.Error(err)) os.Exit(1) diff --git a/cli/forward/tcp.go b/cli/forward/tcp.go index 51094f0..aeb971d 100644 --- a/cli/forward/tcp.go +++ b/cli/forward/tcp.go @@ -30,7 +30,7 @@ Examples: var logger log.Logger - cmd.PreRun = func(cmd *cobra.Command, args []string) { + cmd.PreRun = func(_ *cobra.Command, args []string) { // Discard any ports in the configuration file and use from command // line. conf.Ports = []config.PortConfig{{ @@ -46,7 +46,7 @@ Examples: } } - cmd.Run = func(cmd *cobra.Command, args []string) { + cmd.Run = func(_ *cobra.Command, _ []string) { if err := runForward(conf, logger); err != nil { logger.Error("failed to run forward", zap.Error(err)) os.Exit(1) diff --git a/cli/server/command.go b/cli/server/command.go index 0b67e64..c4ee3f5 100644 --- a/cli/server/command.go +++ b/cli/server/command.go @@ -80,7 +80,7 @@ Examples: var logger log.Logger - cmd.PreRun = func(cmd *cobra.Command, args []string) { + cmd.PreRun = func(_ *cobra.Command, _ []string) { if err := loadConf.Load(&conf); err != nil { fmt.Println(err.Error()) os.Exit(1) @@ -134,7 +134,7 @@ Examples: } } - cmd.Run = func(cmd *cobra.Command, args []string) { + cmd.Run = func(_ *cobra.Command, _ []string) { if err := runServer(&conf, logger); err != nil { logger.Error("failed to run agent", zap.Error(err)) os.Exit(1) diff --git a/cli/server/status/cluster.go b/cli/server/status/cluster.go index 7c3d5b6..da371ec 100644 --- a/cli/server/status/cluster.go +++ b/cli/server/status/cluster.go @@ -37,7 +37,7 @@ Examples: `, } - cmd.Run = func(cmd *cobra.Command, args []string) { + cmd.Run = func(_ *cobra.Command, _ []string) { showClusterNodes(c) } @@ -88,7 +88,7 @@ Examples: `, } - cmd.Run = func(cmd *cobra.Command, args []string) { + cmd.Run = func(_ *cobra.Command, args []string) { showClusterNode(args[0], c) } diff --git a/cli/server/status/command.go b/cli/server/status/command.go index e7a62d9..edacd1c 100644 --- a/cli/server/status/command.go +++ b/cli/server/status/command.go @@ -38,7 +38,7 @@ Examples: c := client.NewClient(nil) - cmd.PersistentPreRun = func(cmd *cobra.Command, args []string) { + cmd.PersistentPreRun = func(_ *cobra.Command, _ []string) { if err := conf.Validate(); err != nil { fmt.Printf("config: %s\n", err.Error()) os.Exit(1) diff --git a/cli/server/status/gossip.go b/cli/server/status/gossip.go index 8af8e95..294ca2f 100644 --- a/cli/server/status/gossip.go +++ b/cli/server/status/gossip.go @@ -37,7 +37,7 @@ Examples: `, } - cmd.Run = func(cmd *cobra.Command, args []string) { + cmd.Run = func(_ *cobra.Command, _ []string) { showGossipNodes(c) } @@ -83,7 +83,7 @@ Examples: `, } - cmd.Run = func(cmd *cobra.Command, args []string) { + cmd.Run = func(_ *cobra.Command, args []string) { showGossipNode(args[0], c) } diff --git a/cli/server/status/upstream.go b/cli/server/status/upstream.go index e06dd50..40897c4 100644 --- a/cli/server/status/upstream.go +++ b/cli/server/status/upstream.go @@ -33,7 +33,7 @@ Examples: `, } - cmd.Run = func(cmd *cobra.Command, args []string) { + cmd.Run = func(_ *cobra.Command, _ []string) { showUpstreamEndpoints(c) } diff --git a/cli/workload/requests.go b/cli/workload/requests.go index 993017c..0aa1b27 100644 --- a/cli/workload/requests.go +++ b/cli/workload/requests.go @@ -55,7 +55,7 @@ Examples: // Register flags and set default values. conf.RegisterFlags(cmd.Flags()) - cmd.Run = func(cmd *cobra.Command, args []string) { + cmd.Run = func(_ *cobra.Command, _ []string) { if err := conf.Validate(); err != nil { fmt.Printf("invalid config: %s\n", err.Error()) os.Exit(1) diff --git a/cli/workload/upstreams.go b/cli/workload/upstreams.go index 7a8000c..fa47060 100644 --- a/cli/workload/upstreams.go +++ b/cli/workload/upstreams.go @@ -50,7 +50,7 @@ Examples: // Register flags and set default values. conf.RegisterFlags(cmd.Flags()) - cmd.Run = func(cmd *cobra.Command, args []string) { + cmd.Run = func(_ *cobra.Command, _ []string) { if err := conf.Validate(); err != nil { fmt.Printf("invalid config: %s\n", err.Error()) os.Exit(1) diff --git a/pkg/log/logger.go b/pkg/log/logger.go index 522627f..3fe7d84 100644 --- a/pkg/log/logger.go +++ b/pkg/log/logger.go @@ -220,7 +220,7 @@ func (l *nopLogger) Sync() error { func (l *nopLogger) StdLogger(_ zapcore.Level) *stdlog.Logger { return stdlog.New(&loggerWriter{ - logFunc: func(msg string, fields ...zap.Field) { + logFunc: func(_ string, _ ...zap.Field) { }, }, "", 0) } diff --git a/server/proxy/httpproxy_test.go b/server/proxy/httpproxy_test.go index affeae0..1311de8 100644 --- a/server/proxy/httpproxy_test.go +++ b/server/proxy/httpproxy_test.go @@ -71,6 +71,8 @@ func TestHTTPProxy_Forward(t *testing.T) { proxy := NewHTTPProxy( &fakeManager{ handler: func(endpointID string, allowForward bool) (upstream.Upstream, bool) { + assert.Equal(t, "my-endpoint", endpointID) + assert.True(t, allowForward) return &tcpUpstream{ addr: server.Listener.Addr().String(), }, true @@ -101,7 +103,7 @@ func TestHTTPProxy_Forward(t *testing.T) { t.Run("timeout", func(t *testing.T) { blockCh := make(chan struct{}) server := httptest.NewServer(http.HandlerFunc( - func(w http.ResponseWriter, r *http.Request) { + func(_ http.ResponseWriter, _ *http.Request) { <-blockCh }, )) @@ -111,6 +113,8 @@ func TestHTTPProxy_Forward(t *testing.T) { proxy := NewHTTPProxy( &fakeManager{ handler: func(endpointID string, allowForward bool) (upstream.Upstream, bool) { + assert.Equal(t, "my-endpoint", endpointID) + assert.True(t, allowForward) return &tcpUpstream{ addr: server.Listener.Addr().String(), }, true @@ -121,6 +125,7 @@ func TestHTTPProxy_Forward(t *testing.T) { ) r := httptest.NewRequest(http.MethodGet, "/", nil) + r.Header.Add("x-piko-endpoint", "my-endpoint") w := httptest.NewRecorder() proxy.ServeHTTP(w, r) @@ -139,6 +144,8 @@ func TestHTTPProxy_Forward(t *testing.T) { proxy := NewHTTPProxy( &fakeManager{ handler: func(endpointID string, allowForward bool) (upstream.Upstream, bool) { + assert.Equal(t, "my-endpoint", endpointID) + assert.True(t, allowForward) return &tcpUpstream{ addr: "localhost:55555", }, true diff --git a/server/proxy/tcpproxy_test.go b/server/proxy/tcpproxy_test.go index c7d468a..d3127df 100644 --- a/server/proxy/tcpproxy_test.go +++ b/server/proxy/tcpproxy_test.go @@ -49,6 +49,8 @@ func TestTCPProxy_Forward(t *testing.T) { server := NewServer( &fakeManager{ handler: func(endpointID string, allowForward bool) (upstream.Upstream, bool) { + assert.Equal(t, "my-endpoint", endpointID) + assert.True(t, allowForward) return &tcpUpstream{ addr: echoLn.Addr().String(), }, true @@ -91,6 +93,8 @@ func TestTCPProxy_Forward(t *testing.T) { proxy := NewTCPProxy( &fakeManager{ handler: func(endpointID string, allowForward bool) (upstream.Upstream, bool) { + assert.Equal(t, "my-endpoint", endpointID) + assert.True(t, allowForward) return &tcpUpstream{ addr: "localhost:55555", }, true diff --git a/tests/cluster_test.go b/tests/cluster_test.go index d20a73d..82a98ca 100644 --- a/tests/cluster_test.go +++ b/tests/cluster_test.go @@ -26,7 +26,7 @@ func TestCluster_Proxy(t *testing.T) { remoteEndpointCh := make(chan string) cluster.Nodes()[1].ClusterState().OnRemoteEndpointUpdate( - func(nodeID string, endpointID string) { + func(_ string, endpointID string) { remoteEndpointCh <- endpointID }, ) @@ -39,7 +39,7 @@ func TestCluster_Proxy(t *testing.T) { assert.NoError(t, err) server := httptest.NewUnstartedServer(http.HandlerFunc( - func(w http.ResponseWriter, r *http.Request) {}, + func(_ http.ResponseWriter, _ *http.Request) {}, )) server.Listener = ln go server.Start() @@ -72,7 +72,7 @@ func TestCluster_Proxy(t *testing.T) { remoteEndpointCh := make(chan string) cluster.Nodes()[1].ClusterState().OnRemoteEndpointUpdate( - func(nodeID string, endpointID string) { + func(_ string, endpointID string) { remoteEndpointCh <- endpointID }, )