From 29efac3e5e9e9c5b6a6bbc78563f495fde434648 Mon Sep 17 00:00:00 2001 From: Ludovic Fernandez Date: Thu, 26 Sep 2019 11:00:06 +0200 Subject: [PATCH] fix: update linter. --- .golangci.toml | 2 ++ cmd/traefik/traefik.go | 1 - integration/error_pages_test.go | 1 - integration/grpc_test.go | 2 -- integration/healthcheck_test.go | 3 --- integration/simple_test.go | 5 +---- integration/tcp_test.go | 1 - integration/tracing_test.go | 1 - integration/websocket_test.go | 3 --- pkg/cli/commands_test.go | 2 -- pkg/cli/file_finder_test.go | 1 - pkg/config/dynamic/middlewares.go | 1 - pkg/config/parser/nodes_metadata.go | 1 - pkg/config/runtime/runtime_test.go | 1 - pkg/config/static/entrypoints.go | 4 ++-- pkg/log/log_test.go | 1 - pkg/metrics/influxdb_test.go | 1 - pkg/metrics/prometheus_test.go | 1 - pkg/middlewares/accesslog/field_middleware.go | 1 - pkg/middlewares/accesslog/logger_formatters.go | 2 +- pkg/middlewares/accesslog/logger_formatters_test.go | 2 -- pkg/middlewares/accesslog/logger_test.go | 2 -- pkg/middlewares/auth/forward_test.go | 1 - pkg/middlewares/headers/headers_test.go | 1 - .../passtlsclientcert/pass_tls_client_cert_test.go | 4 ---- pkg/middlewares/pipelining/pipelining.go | 1 - pkg/middlewares/ratelimiter/rate_limiter_test.go | 1 - pkg/middlewares/redirect/redirect_regex_test.go | 9 +++------ pkg/middlewares/redirect/redirect_scheme_test.go | 9 +++------ pkg/middlewares/replacepath/replace_path_test.go | 1 - .../replacepathregex/replace_path_regex_test.go | 1 - pkg/middlewares/tracing/entrypoint_test.go | 1 - pkg/middlewares/tracing/forwarder_test.go | 1 - pkg/provider/acme/local_store.go | 1 - pkg/provider/acme/provider.go | 1 - pkg/provider/docker/docker.go | 5 ++--- pkg/provider/file/file_test.go | 1 - pkg/provider/kubernetes/crd/kubernetes.go | 1 - pkg/provider/kubernetes/crd/kubernetes_tcp.go | 2 -- pkg/provider/kubernetes/ingress/kubernetes.go | 2 -- pkg/provider/marathon/marathon.go | 1 - pkg/provider/rancher/config.go | 2 -- pkg/provider/rest/rest.go | 1 - pkg/server/router/router_test.go | 5 +---- pkg/server/server_entrypoint_tcp_test.go | 2 +- pkg/server/service/loadbalancer/wrr/wrr_test.go | 1 - pkg/server/service/proxy_websocket_test.go | 4 ---- pkg/server/service/service_test.go | 1 - pkg/server/service/tcp/service.go | 1 - pkg/tls/certificate.go | 3 --- pkg/tls/certificate_store.go | 1 - pkg/types/logs.go | 2 +- 52 files changed, 17 insertions(+), 89 deletions(-) diff --git a/.golangci.toml b/.golangci.toml index 995580a8b..73475dcb2 100644 --- a/.golangci.toml +++ b/.golangci.toml @@ -40,7 +40,9 @@ "scopelint", "gochecknoinits", "gochecknoglobals", +# "godox", # manage TODO FIXME ## wait for https://github.com/golangci/golangci-lint/issues/337 "bodyclose", # Too many false-positive and panics. +# "stylecheck", # skip because report issues related to some generated files. ## wait for https://github.com/golangci/golangci-lint/issues/337 ] [issues] diff --git a/cmd/traefik/traefik.go b/cmd/traefik/traefik.go index d0d55e55d..b551e0926 100644 --- a/cmd/traefik/traefik.go +++ b/cmd/traefik/traefik.go @@ -119,7 +119,6 @@ func runCmd(staticConfiguration *static.Configuration) error { return fmt.Errorf("error while building entryPoint %s: %v", entryPointName, err) } serverEntryPointsTCP[entryPointName].RouteAppenderFactory = router.NewRouteAppenderFactory(*staticConfiguration, entryPointName, acmeProviders) - } svr := server.NewServer(*staticConfiguration, providerAggregator, serverEntryPointsTCP, tlsManager) diff --git a/integration/error_pages_test.go b/integration/error_pages_test.go index 5a4fd4afb..5b218bbe8 100644 --- a/integration/error_pages_test.go +++ b/integration/error_pages_test.go @@ -47,7 +47,6 @@ func (s *ErrorPagesSuite) TestSimpleConfiguration(c *check.C) { } func (s *ErrorPagesSuite) TestErrorPage(c *check.C) { - // error.toml contains a mis-configuration of the backend host file := s.adaptFile(c, "fixtures/error_pages/error.toml", struct { Server1 string diff --git a/integration/grpc_test.go b/integration/grpc_test.go index d79ed0009..074596e51 100644 --- a/integration/grpc_test.go +++ b/integration/grpc_test.go @@ -90,7 +90,6 @@ func getHelloClientGRPC() (helloworld.GreeterClient, func() error, error) { return nil, func() error { return nil }, err } return helloworld.NewGreeterClient(conn), conn.Close, nil - } func getHelloClientGRPCh2c() (helloworld.GreeterClient, func() error, error) { @@ -99,7 +98,6 @@ func getHelloClientGRPCh2c() (helloworld.GreeterClient, func() error, error) { return nil, func() error { return nil }, err } return helloworld.NewGreeterClient(conn), conn.Close, nil - } func callHelloClientGRPC(name string, secure bool) (string, error) { diff --git a/integration/healthcheck_test.go b/integration/healthcheck_test.go index 110ba08eb..999c69a9a 100644 --- a/integration/healthcheck_test.go +++ b/integration/healthcheck_test.go @@ -27,7 +27,6 @@ func (s *HealthCheckSuite) SetUpSuite(c *check.C) { } func (s *HealthCheckSuite) TestSimpleConfiguration(c *check.C) { - file := s.adaptFile(c, "fixtures/healthcheck/simple.toml", struct { Server1 string Server2 string @@ -166,7 +165,6 @@ func (s *HealthCheckSuite) TestMultipleEntrypoints(c *check.C) { } func (s *HealthCheckSuite) TestPortOverload(c *check.C) { - // Set one whoami health to 200 client := &http.Client{} statusInternalServerErrorReq, err := http.NewRequest(http.MethodPost, "http://"+s.whoami1IP+"/health", bytes.NewBuffer([]byte("200"))) @@ -206,5 +204,4 @@ func (s *HealthCheckSuite) TestPortOverload(c *check.C) { // Verify no backend service is available due to failing health checks err = try.Request(frontendHealthReq, 3*time.Second, try.StatusCodeIs(http.StatusServiceUnavailable)) c.Assert(err, checker.IsNil) - } diff --git a/integration/simple_test.go b/integration/simple_test.go index 55075163a..49c35d13f 100644 --- a/integration/simple_test.go +++ b/integration/simple_test.go @@ -193,7 +193,6 @@ func (s *SimpleSuite) TestStatsWithMultipleEntryPoint(c *check.C) { err = try.GetRequest("http://127.0.0.1:8080/health", 1*time.Second, try.BodyContains(`"total_status_code_count":{"200":2}`)) c.Assert(err, checker.IsNil) - } func (s *SimpleSuite) TestNoAuthOnPing(c *check.C) { @@ -301,7 +300,6 @@ func (s *SimpleSuite) TestMultipleProviderSameBackendName(c *check.C) { err = try.GetRequest("http://127.0.0.1:8000/file", 1*time.Second, try.BodyContains(ipWhoami02)) c.Assert(err, checker.IsNil) - } func (s *SimpleSuite) TestIPStrategyWhitelist(c *check.C) { @@ -449,7 +447,6 @@ func (s *SimpleSuite) TestMultiProvider(c *check.C) { err = try.GetRequest("http://127.0.0.1:8000/", 1*time.Second, try.StatusCodeIs(http.StatusOK), try.BodyContains("CustomValue")) c.Assert(err, checker.IsNil) - } func (s *SimpleSuite) TestSimpleConfigurationHostRequestTrailingPeriod(c *check.C) { @@ -625,8 +622,8 @@ func (s *SimpleSuite) TestWRRSticky(c *check.C) { repartition := map[string]int{} req, err := http.NewRequest(http.MethodGet, "http://127.0.0.1:8000/whoami", nil) c.Assert(err, checker.IsNil) - for i := 0; i < 4; i++ { + for i := 0; i < 4; i++ { response, err := http.DefaultClient.Do(req) c.Assert(err, checker.IsNil) c.Assert(response.StatusCode, checker.Equals, http.StatusOK) diff --git a/integration/tcp_test.go b/integration/tcp_test.go index ba49b3fdb..75015df95 100644 --- a/integration/tcp_test.go +++ b/integration/tcp_test.go @@ -230,7 +230,6 @@ func guessWhoTLSMaxVersion(addr, serverName string, tlsCall bool, tlsMaxVersion var err error if tlsCall { - conn, err = tls.Dial("tcp", addr, &tls.Config{ ServerName: serverName, InsecureSkipVerify: true, diff --git a/integration/tracing_test.go b/integration/tracing_test.go index 0dbf009c5..07b1d3438 100644 --- a/integration/tracing_test.go +++ b/integration/tracing_test.go @@ -88,7 +88,6 @@ func (s *TracingSuite) TestZipkinRateLimit(c *check.C) { err = try.GetRequest("http://"+s.IP+":9411/api/v2/spans?serviceName=tracing", 20*time.Second, try.BodyContains("forward service1/router1@file", "ratelimit-1@file")) c.Assert(err, checker.IsNil) - } func (s *TracingSuite) TestZipkinRetry(c *check.C) { diff --git a/integration/websocket_test.go b/integration/websocket_test.go index e2c834cd4..99b0a77e5 100644 --- a/integration/websocket_test.go +++ b/integration/websocket_test.go @@ -177,7 +177,6 @@ func (s *WebsocketSuite) TestOrigin(c *check.C) { c.Assert(err, checker.IsNil) c.Assert(n, checker.Equals, 2) c.Assert(string(msg), checker.Equals, "OK") - } func (s *WebsocketSuite) TestWrongOriginIgnoredByServer(c *check.C) { @@ -238,7 +237,6 @@ func (s *WebsocketSuite) TestWrongOriginIgnoredByServer(c *check.C) { c.Assert(err, checker.IsNil) c.Assert(n, checker.Equals, 2) c.Assert(string(msg), checker.Equals, "OK") - } func (s *WebsocketSuite) TestSSLTermination(c *check.C) { @@ -389,7 +387,6 @@ func (s *WebsocketSuite) TestSpecificResponseFromBackend(c *check.C) { _, resp, err := gorillawebsocket.DefaultDialer.Dial("ws://127.0.0.1:8000/ws", nil) c.Assert(err, checker.NotNil) c.Assert(resp.StatusCode, check.Equals, http.StatusUnauthorized) - } func (s *WebsocketSuite) TestURLWithURLEncodedChar(c *check.C) { diff --git a/pkg/cli/commands_test.go b/pkg/cli/commands_test.go index 3796369ea..a74a1d54a 100644 --- a/pkg/cli/commands_test.go +++ b/pkg/cli/commands_test.go @@ -82,7 +82,6 @@ func Test_execute(t *testing.T) { return nil }, } - }, expected: expected{result: "root"}, }, @@ -99,7 +98,6 @@ func Test_execute(t *testing.T) { return nil }, } - }, expected: expected{error: true}, }, diff --git a/pkg/cli/file_finder_test.go b/pkg/cli/file_finder_test.go index 53acfe382..c0b8971c1 100644 --- a/pkg/cli/file_finder_test.go +++ b/pkg/cli/file_finder_test.go @@ -85,7 +85,6 @@ func TestFinder_Find(t *testing.T) { for _, test := range testCases { t.Run(test.desc, func(t *testing.T) { - finder := Finder{ BasePaths: test.basePaths, Extensions: []string{"toml", "yaml", "yml"}, diff --git a/pkg/config/dynamic/middlewares.go b/pkg/config/dynamic/middlewares.go index b8fb8df27..a627ce621 100644 --- a/pkg/config/dynamic/middlewares.go +++ b/pkg/config/dynamic/middlewares.go @@ -460,7 +460,6 @@ func (c *ClientTLS) CreateTLSConfig() (*tls.Config, error) { cert, err = tls.X509KeyPair([]byte(c.Cert), []byte(c.Key)) if err != nil { return nil, fmt.Errorf("failed to load TLS keypair: %v", err) - } } else { return nil, fmt.Errorf("TLS key is a file, but tls cert is not") diff --git a/pkg/config/parser/nodes_metadata.go b/pkg/config/parser/nodes_metadata.go index 170145caf..3ee3d0982 100644 --- a/pkg/config/parser/nodes_metadata.go +++ b/pkg/config/parser/nodes_metadata.go @@ -130,7 +130,6 @@ func findTypedField(rType reflect.Type, node *Node) (reflect.StructField, error) return cField, nil } } - } return reflect.StructField{}, fmt.Errorf("field not found, node: %s", node.Name) diff --git a/pkg/config/runtime/runtime_test.go b/pkg/config/runtime/runtime_test.go index 5ff0a97d6..1cdce84a6 100644 --- a/pkg/config/runtime/runtime_test.go +++ b/pkg/config/runtime/runtime_test.go @@ -687,5 +687,4 @@ func TestPopulateUsedBy(t *testing.T) { } }) } - } diff --git a/pkg/config/static/entrypoints.go b/pkg/config/static/entrypoints.go index 544bb8386..ff3088ad3 100644 --- a/pkg/config/static/entrypoints.go +++ b/pkg/config/static/entrypoints.go @@ -32,8 +32,8 @@ type EntryPoints map[string]*EntryPoint // EntryPointsTransport configures communication between clients and Traefik. type EntryPointsTransport struct { - LifeCycle *LifeCycle `description:"Timeouts influencing the server life cycle." json:"lifeCycle,omitempty" toml:"lifeCycle,omitempty" yaml:"lifeCycle,omitempty" export:"true" export:"true"` - RespondingTimeouts *RespondingTimeouts `description:"Timeouts for incoming requests to the Traefik instance." json:"respondingTimeouts,omitempty" toml:"respondingTimeouts,omitempty" yaml:"respondingTimeouts,omitempty" export:"true" export:"true"` + LifeCycle *LifeCycle `description:"Timeouts influencing the server life cycle." json:"lifeCycle,omitempty" toml:"lifeCycle,omitempty" yaml:"lifeCycle,omitempty" export:"true"` + RespondingTimeouts *RespondingTimeouts `description:"Timeouts for incoming requests to the Traefik instance." json:"respondingTimeouts,omitempty" toml:"respondingTimeouts,omitempty" yaml:"respondingTimeouts,omitempty" export:"true"` } // SetDefaults sets the default values. diff --git a/pkg/log/log_test.go b/pkg/log/log_test.go index e4ce53221..c81724ff3 100644 --- a/pkg/log/log_test.go +++ b/pkg/log/log_test.go @@ -40,7 +40,6 @@ func TestLog(t *testing.T) { for _, test := range testCases { test := test t.Run(test.desc, func(t *testing.T) { - var buffer bytes.Buffer SetOutput(&buffer) diff --git a/pkg/metrics/influxdb_test.go b/pkg/metrics/influxdb_test.go index 10df13633..7ebc09997 100644 --- a/pkg/metrics/influxdb_test.go +++ b/pkg/metrics/influxdb_test.go @@ -60,7 +60,6 @@ func TestInfluxDB(t *testing.T) { influxDBRegistry.EntryPointReqsCounter().With("entrypoint", "test").Add(1) influxDBRegistry.EntryPointReqDurationHistogram().With("entrypoint", "test").Observe(10000) influxDBRegistry.EntryPointOpenConnsGauge().With("entrypoint", "test").Set(1) - }) assertMessage(t, msgEntrypoint, expectedEntrypoint) diff --git a/pkg/metrics/prometheus_test.go b/pkg/metrics/prometheus_test.go index 7c0c5ed02..13eb3e874 100644 --- a/pkg/metrics/prometheus_test.go +++ b/pkg/metrics/prometheus_test.go @@ -269,7 +269,6 @@ func TestPrometheus(t *testing.T) { } test.assert(family) }) - } } diff --git a/pkg/middlewares/accesslog/field_middleware.go b/pkg/middlewares/accesslog/field_middleware.go index f5007a1ca..19b455939 100644 --- a/pkg/middlewares/accesslog/field_middleware.go +++ b/pkg/middlewares/accesslog/field_middleware.go @@ -45,7 +45,6 @@ func AddServiceFields(rw http.ResponseWriter, req *http.Request, next http.Handl data.Core[ServiceAddr] = req.URL.Host next.ServeHTTP(rw, req) - } // AddOriginFields add origin fields diff --git a/pkg/middlewares/accesslog/logger_formatters.go b/pkg/middlewares/accesslog/logger_formatters.go index 554e709b3..5abb996d7 100644 --- a/pkg/middlewares/accesslog/logger_formatters.go +++ b/pkg/middlewares/accesslog/logger_formatters.go @@ -69,8 +69,8 @@ func toLog(fields logrus.Fields, key string, defaultValue string, quoted bool) i return v } } - return defaultValue + return defaultValue } func toLogEntry(s string, defaultValue string, quote bool) string { diff --git a/pkg/middlewares/accesslog/logger_formatters_test.go b/pkg/middlewares/accesslog/logger_formatters_test.go index 4817c26d9..ce3c6aec5 100644 --- a/pkg/middlewares/accesslog/logger_formatters_test.go +++ b/pkg/middlewares/accesslog/logger_formatters_test.go @@ -99,11 +99,9 @@ func TestCommonLogFormatter_Format(t *testing.T) { assert.Equal(t, test.expectedLog, string(raw)) }) } - } func Test_toLog(t *testing.T) { - testCases := []struct { desc string fields logrus.Fields diff --git a/pkg/middlewares/accesslog/logger_test.go b/pkg/middlewares/accesslog/logger_test.go index f133ae530..b93d8fdcd 100644 --- a/pkg/middlewares/accesslog/logger_test.go +++ b/pkg/middlewares/accesslog/logger_test.go @@ -527,7 +527,6 @@ func TestNewLogHandlerOutputStdout(t *testing.T) { for _, test := range testCases { test := test t.Run(test.desc, func(t *testing.T) { - // NOTE: It is not possible to run these cases in parallel because we capture Stdout file, restoreStdout := captureStdout(t) @@ -543,7 +542,6 @@ func TestNewLogHandlerOutputStdout(t *testing.T) { } func assertValidLogData(t *testing.T, expected string, logData []byte) { - if len(expected) == 0 { assert.Zero(t, len(logData)) t.Log(string(logData)) diff --git a/pkg/middlewares/auth/forward_test.go b/pkg/middlewares/auth/forward_test.go index a816fb813..20dfa6608 100644 --- a/pkg/middlewares/auth/forward_test.go +++ b/pkg/middlewares/auth/forward_test.go @@ -367,7 +367,6 @@ func Test_writeHeader(t *testing.T) { for _, test := range testCases { t.Run(test.name, func(t *testing.T) { - req := testhelpers.MustNewRequest(http.MethodGet, "http://foo.bar/path?q=1", nil) for key, value := range test.headers { req.Header.Set(key, value) diff --git a/pkg/middlewares/headers/headers_test.go b/pkg/middlewares/headers/headers_test.go index 592be7a02..21df2deff 100644 --- a/pkg/middlewares/headers/headers_test.go +++ b/pkg/middlewares/headers/headers_test.go @@ -327,7 +327,6 @@ func TestGetTracingInformation(t *testing.T) { assert.Equal(t, "testing", name) assert.Equal(t, tracing.SpanKindNoneEnum, trace) - } func TestCORSResponses(t *testing.T) { diff --git a/pkg/middlewares/passtlsclientcert/pass_tls_client_cert_test.go b/pkg/middlewares/passtlsclientcert/pass_tls_client_cert_test.go index 5ba15c535..8bf5b2e50 100644 --- a/pkg/middlewares/passtlsclientcert/pass_tls_client_cert_test.go +++ b/pkg/middlewares/passtlsclientcert/pass_tls_client_cert_test.go @@ -360,7 +360,6 @@ WqeUSNGYV//RunTeuRDAf5OxehERb1srzBXhRZ3cZdzXbgR/`), require.Equal(t, test.expected, sanitize(test.toSanitize), "The sanitized certificates should be equal") }) } - } func TestTLSClientHeadersWithPEM(t *testing.T) { @@ -429,7 +428,6 @@ func TestTLSClientHeadersWithPEM(t *testing.T) { require.Empty(t, res.Header().Get(xForwardedTLSClientCert), "The response header should be always empty") }) } - } func TestGetSans(t *testing.T) { @@ -478,7 +476,6 @@ func TestGetSans(t *testing.T) { } }) } - } func TestTLSClientHeadersWithCertInfo(t *testing.T) { @@ -659,5 +656,4 @@ func TestTLSClientHeadersWithCertInfo(t *testing.T) { require.Empty(t, res.Header().Get(xForwardedTLSClientCertInfo), "The response header should be always empty") }) } - } diff --git a/pkg/middlewares/pipelining/pipelining.go b/pkg/middlewares/pipelining/pipelining.go index a4e14110a..4124b552f 100644 --- a/pkg/middlewares/pipelining/pipelining.go +++ b/pkg/middlewares/pipelining/pipelining.go @@ -35,7 +35,6 @@ func (p *pipelining) ServeHTTP(rw http.ResponseWriter, r *http.Request) { } else { p.next.ServeHTTP(&writerWithoutCloseNotify{rw}, r) } - } // writerWithoutCloseNotify helps to disable closeNotify diff --git a/pkg/middlewares/ratelimiter/rate_limiter_test.go b/pkg/middlewares/ratelimiter/rate_limiter_test.go index ad4474870..7136d7ca0 100644 --- a/pkg/middlewares/ratelimiter/rate_limiter_test.go +++ b/pkg/middlewares/ratelimiter/rate_limiter_test.go @@ -142,7 +142,6 @@ func TestRateLimit(t *testing.T) { for _, test := range testCases { test := test t.Run(test.desc, func(t *testing.T) { - t.Parallel() reqCount := 0 diff --git a/pkg/middlewares/redirect/redirect_regex_test.go b/pkg/middlewares/redirect/redirect_regex_test.go index 9a3882003..ca4edbb79 100644 --- a/pkg/middlewares/redirect/redirect_regex_test.go +++ b/pkg/middlewares/redirect/redirect_regex_test.go @@ -179,16 +179,13 @@ func TestRedirectRegexHandler(t *testing.T) { handler.ServeHTTP(recorder, r) assert.Equal(t, test.expectedStatus, recorder.Code) - if test.expectedStatus == http.StatusMovedPermanently || - test.expectedStatus == http.StatusFound || - test.expectedStatus == http.StatusTemporaryRedirect || - test.expectedStatus == http.StatusPermanentRedirect { - + switch test.expectedStatus { + case http.StatusMovedPermanently, http.StatusFound, http.StatusTemporaryRedirect, http.StatusPermanentRedirect: location, err := recorder.Result().Location() require.NoError(t, err) assert.Equal(t, test.expectedURL, location.String()) - } else { + default: location, err := recorder.Result().Location() require.Errorf(t, err, "Location %v", location) } diff --git a/pkg/middlewares/redirect/redirect_scheme_test.go b/pkg/middlewares/redirect/redirect_scheme_test.go index 7000912db..384780d53 100644 --- a/pkg/middlewares/redirect/redirect_scheme_test.go +++ b/pkg/middlewares/redirect/redirect_scheme_test.go @@ -206,16 +206,14 @@ func TestRedirectSchemeHandler(t *testing.T) { handler.ServeHTTP(recorder, r) assert.Equal(t, test.expectedStatus, recorder.Code) - if test.expectedStatus == http.StatusMovedPermanently || - test.expectedStatus == http.StatusFound || - test.expectedStatus == http.StatusTemporaryRedirect || - test.expectedStatus == http.StatusPermanentRedirect { + switch test.expectedStatus { + case http.StatusMovedPermanently, http.StatusFound, http.StatusTemporaryRedirect, http.StatusPermanentRedirect: location, err := recorder.Result().Location() require.NoError(t, err) assert.Equal(t, test.expectedURL, location.String()) - } else { + default: location, err := recorder.Result().Location() require.Errorf(t, err, "Location %v", location) } @@ -234,7 +232,6 @@ func TestRedirectSchemeHandler(t *testing.T) { test.expectedStatus == http.StatusFound || test.expectedStatus == http.StatusTemporaryRedirect || test.expectedStatus == http.StatusPermanentRedirect { - location, err := recorder.Result().Location() require.NoError(t, err) diff --git a/pkg/middlewares/replacepath/replace_path_test.go b/pkg/middlewares/replacepath/replace_path_test.go index ca9e03e81..65824dcde 100644 --- a/pkg/middlewares/replacepath/replace_path_test.go +++ b/pkg/middlewares/replacepath/replace_path_test.go @@ -23,7 +23,6 @@ func TestReplacePath(t *testing.T) { for _, path := range paths { t.Run(path, func(t *testing.T) { - var expectedPath, actualHeader, requestURI string next := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { expectedPath = r.URL.Path diff --git a/pkg/middlewares/replacepathregex/replace_path_regex_test.go b/pkg/middlewares/replacepathregex/replace_path_regex_test.go index d865a5cc2..8215df968 100644 --- a/pkg/middlewares/replacepathregex/replace_path_regex_test.go +++ b/pkg/middlewares/replacepathregex/replace_path_regex_test.go @@ -74,7 +74,6 @@ func TestReplacePathRegex(t *testing.T) { for _, test := range testCases { t.Run(test.desc, func(t *testing.T) { - var actualPath, actualHeader, requestURI string next := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { actualPath = r.URL.Path diff --git a/pkg/middlewares/tracing/entrypoint_test.go b/pkg/middlewares/tracing/entrypoint_test.go index 2fe090448..79bd89db6 100644 --- a/pkg/middlewares/tracing/entrypoint_test.go +++ b/pkg/middlewares/tracing/entrypoint_test.go @@ -65,7 +65,6 @@ func TestEntryPointMiddleware(t *testing.T) { for _, test := range testCases { t.Run(test.desc, func(t *testing.T) { - newTracing, err := tracing.NewTracing("", test.spanNameLimit, test.tracing) require.NoError(t, err) diff --git a/pkg/middlewares/tracing/forwarder_test.go b/pkg/middlewares/tracing/forwarder_test.go index 7bf911aa0..073df8ad4 100644 --- a/pkg/middlewares/tracing/forwarder_test.go +++ b/pkg/middlewares/tracing/forwarder_test.go @@ -109,7 +109,6 @@ func TestNewForwarder(t *testing.T) { for _, test := range testCases { t.Run(test.desc, func(t *testing.T) { - newTracing, err := tracing.NewTracing("", test.spanNameLimit, test.tracing) require.NoError(t, err) diff --git a/pkg/provider/acme/local_store.go b/pkg/provider/acme/local_store.go index e0786911b..0b76064e3 100644 --- a/pkg/provider/acme/local_store.go +++ b/pkg/provider/acme/local_store.go @@ -171,7 +171,6 @@ func NewLocalChallengeStore() *LocalChallengeStore { TLSChallenges: make(map[string]*Certificate), }, } - } // GetHTTPChallengeToken Get the http challenge token from the store diff --git a/pkg/provider/acme/provider.go b/pkg/provider/acme/provider.go index ecf28a363..300a81899 100644 --- a/pkg/provider/acme/provider.go +++ b/pkg/provider/acme/provider.go @@ -414,7 +414,6 @@ func (p *Provider) watchNewDomains(ctx context.Context) { } p.resolveDomains(ctxRouter, domains, tlsStore) } - } case <-stop: return diff --git a/pkg/provider/docker/docker.go b/pkg/provider/docker/docker.go index 9d3d4c038..901ba9d5d 100644 --- a/pkg/provider/docker/docker.go +++ b/pkg/provider/docker/docker.go @@ -193,10 +193,11 @@ func (p *Provider) Provide(configurationChan chan<- dynamic.Message, pool *safe. if p.Watch { if p.SwarmMode { errChan := make(chan error) + // TODO: This need to be change. Linked to Swarm events docker/docker#23827 ticker := time.NewTicker(time.Duration(p.SwarmModeRefreshSeconds)) - pool.GoCtx(func(ctx context.Context) { + pool.GoCtx(func(ctx context.Context) { ctx = log.With(ctx, log.Str(log.ProviderName, "docker")) logger := log.FromContext(ctx) @@ -229,7 +230,6 @@ func (p *Provider) Provide(configurationChan chan<- dynamic.Message, pool *safe. return err } // channel closed - } else { f := filters.NewArgs() f.Add("type", "container") @@ -256,7 +256,6 @@ func (p *Provider) Provide(configurationChan chan<- dynamic.Message, pool *safe. case configurationChan <- message: case <-ctx.Done(): } - } } diff --git a/pkg/provider/file/file_test.go b/pkg/provider/file/file_test.go index f4892823f..eef8452b3 100644 --- a/pkg/provider/file/file_test.go +++ b/pkg/provider/file/file_test.go @@ -250,7 +250,6 @@ func createProvider(t *testing.T, test ProvideTestCase, watch bool) (*Provider, } if len(test.filePath) > 0 { - var file *os.File if watch { var err error diff --git a/pkg/provider/kubernetes/crd/kubernetes.go b/pkg/provider/kubernetes/crd/kubernetes.go index 9e5f843a2..7c7d59a74 100644 --- a/pkg/provider/kubernetes/crd/kubernetes.go +++ b/pkg/provider/kubernetes/crd/kubernetes.go @@ -225,7 +225,6 @@ func (p *Provider) loadConfigurationFromCRD(ctx context.Context, client Client) PassTLSClientCert: middleware.Spec.PassTLSClientCert, Retry: middleware.Spec.Retry, } - } return conf diff --git a/pkg/provider/kubernetes/crd/kubernetes_tcp.go b/pkg/provider/kubernetes/crd/kubernetes_tcp.go index a5a6b74e8..1a27885d4 100644 --- a/pkg/provider/kubernetes/crd/kubernetes_tcp.go +++ b/pkg/provider/kubernetes/crd/kubernetes_tcp.go @@ -121,9 +121,7 @@ func (p *Provider) loadIngressRouteTCPConfiguration(ctx context.Context, client } conf.Routers[serviceName].TLS.Options = tlsOptionsName - } - } } diff --git a/pkg/provider/kubernetes/ingress/kubernetes.go b/pkg/provider/kubernetes/ingress/kubernetes.go index 51c6257bd..095e310bc 100644 --- a/pkg/provider/kubernetes/ingress/kubernetes.go +++ b/pkg/provider/kubernetes/ingress/kubernetes.go @@ -221,7 +221,6 @@ func loadService(client Client, namespace string, backend v1beta1.IngressBackend var port int32 for _, subset := range endpoints.Subsets { - for _, p := range subset.Ports { if portName == p.Name { port = p.Port @@ -352,7 +351,6 @@ func (p *Provider) loadConfigurationFromIngresses(ctx context.Context, client Cl Service: serviceName, TLS: &dynamic.RouterTLSConfig{}, } - } conf.HTTP.Services[serviceName] = service } diff --git a/pkg/provider/marathon/marathon.go b/pkg/provider/marathon/marathon.go index adef44ab4..78213f8e7 100644 --- a/pkg/provider/marathon/marathon.go +++ b/pkg/provider/marathon/marathon.go @@ -111,7 +111,6 @@ func (p *Provider) Provide(configurationChan chan<- dynamic.Message, pool *safe. logger := log.FromContext(ctx) operation := func() error { - confg := marathon.NewDefaultConfig() confg.URL = p.Endpoint confg.EventsTransport = marathon.EventsTransportSSE diff --git a/pkg/provider/rancher/config.go b/pkg/provider/rancher/config.go index b6bfa9ad8..6efc00173 100644 --- a/pkg/provider/rancher/config.go +++ b/pkg/provider/rancher/config.go @@ -92,7 +92,6 @@ func (p *Provider) buildTCPServiceConfiguration(ctx context.Context, service ran } func (p *Provider) buildServiceConfiguration(ctx context.Context, service rancherData, configuration *dynamic.HTTPConfiguration) error { - serviceName := service.Name if len(configuration.Services) == 0 { @@ -181,7 +180,6 @@ func (p *Provider) addServerTCP(ctx context.Context, service rancherData, loadBa loadBalancer.Servers = servers return nil - } func (p *Provider) addServers(ctx context.Context, service rancherData, loadBalancer *dynamic.ServersLoadBalancer) error { diff --git a/pkg/provider/rest/rest.go b/pkg/provider/rest/rest.go index ed62466de..5363c15a1 100644 --- a/pkg/provider/rest/rest.go +++ b/pkg/provider/rest/rest.go @@ -46,7 +46,6 @@ func (p *Provider) Append(systemRouter *mux.Router) { Methods(http.MethodPut). Path("/api/providers/{provider}"). HandlerFunc(func(response http.ResponseWriter, request *http.Request) { - vars := mux.Vars(request) if vars["provider"] != "rest" { response.WriteHeader(http.StatusBadRequest) diff --git a/pkg/server/router/router_test.go b/pkg/server/router/router_test.go index 36ee65a6e..654bde6d0 100644 --- a/pkg/server/router/router_test.go +++ b/pkg/server/router/router_test.go @@ -399,7 +399,6 @@ func TestAccessLog(t *testing.T) { for _, test := range testCases { t.Run(test.desc, func(t *testing.T) { - rtConf := runtime.NewConfig(dynamic.Configuration{ HTTP: &dynamic.HTTPConfiguration{ Services: test.serviceConfig, @@ -407,6 +406,7 @@ func TestAccessLog(t *testing.T) { Middlewares: test.middlewaresConfig, }, }) + serviceManager := service.NewManager(rtConf.Services, http.DefaultTransport, nil, nil, nil, nil) middlewaresBuilder := middleware.NewBuilder(rtConf.Middlewares, serviceManager) responseModifierFactory := responsemodifiers.NewBuilder(rtConf.Middlewares) @@ -722,7 +722,6 @@ func TestRuntimeConfiguration(t *testing.T) { assert.Equal(t, test.expectedError, allErrors) }) } - } func TestProviderOnMiddlewares(t *testing.T) { @@ -833,7 +832,6 @@ func BenchmarkRouterServe(b *testing.B) { for i := 0; i < b.N; i++ { reqHost.ServeHTTP(w, req, handlers["web"].ServeHTTP) } - } func BenchmarkService(b *testing.B) { @@ -868,5 +866,4 @@ func BenchmarkService(b *testing.B) { for i := 0; i < b.N; i++ { handler.ServeHTTP(w, req) } - } diff --git a/pkg/server/server_entrypoint_tcp_test.go b/pkg/server/server_entrypoint_tcp_test.go index 6bdce2a55..17ccd81a1 100644 --- a/pkg/server/server_entrypoint_tcp_test.go +++ b/pkg/server/server_entrypoint_tcp_test.go @@ -77,8 +77,8 @@ func TestShutdownHTTPHijacked(t *testing.T) { resp := http.Response{StatusCode: http.StatusOK} err = resp.Write(conn) require.NoError(t, err) - })) + entryPoint.switchRouter(router) conn, err := net.Dial("tcp", entryPoint.listener.Addr().String()) diff --git a/pkg/server/service/loadbalancer/wrr/wrr_test.go b/pkg/server/service/loadbalancer/wrr/wrr_test.go index b2eb65e5a..b6e2761fa 100644 --- a/pkg/server/service/loadbalancer/wrr/wrr_test.go +++ b/pkg/server/service/loadbalancer/wrr/wrr_test.go @@ -19,7 +19,6 @@ type responseRecorder struct { func (r *responseRecorder) WriteHeader(statusCode int) { r.save[r.Header().Get("server")]++ r.ResponseRecorder.WriteHeader(statusCode) - } func TestBalancer(t *testing.T) { diff --git a/pkg/server/service/proxy_websocket_test.go b/pkg/server/service/proxy_websocket_test.go index 6772b0e16..1e4239cf9 100644 --- a/pkg/server/service/proxy_websocket_test.go +++ b/pkg/server/service/proxy_websocket_test.go @@ -139,7 +139,6 @@ func TestWebSocketEcho(t *testing.T) { err = conn.Close() require.NoError(t, err) - })) srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) { @@ -169,7 +168,6 @@ func TestWebSocketEcho(t *testing.T) { err = conn.Close() require.NoError(t, err) - } func TestWebSocketPassHost(t *testing.T) { @@ -215,7 +213,6 @@ func TestWebSocketPassHost(t *testing.T) { err = conn.Close() require.NoError(t, err) - })) srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) { @@ -246,7 +243,6 @@ func TestWebSocketPassHost(t *testing.T) { err = conn.Close() require.NoError(t, err) - }) } } diff --git a/pkg/server/service/service_test.go b/pkg/server/service/service_test.go index 9fb0edd09..1c2cdbf8c 100644 --- a/pkg/server/service/service_test.go +++ b/pkg/server/service/service_test.go @@ -258,7 +258,6 @@ func TestGetLoadBalancerServiceHandler(t *testing.T) { for _, test := range testCases { test := test t.Run(test.desc, func(t *testing.T) { - handler, err := sm.getLoadBalancerServiceHandler(context.Background(), test.serviceName, test.service, test.responseModifier) assert.NoError(t, err) diff --git a/pkg/server/service/tcp/service.go b/pkg/server/service/tcp/service.go index ca52ad72a..072ffbd12 100644 --- a/pkg/server/service/tcp/service.go +++ b/pkg/server/service/tcp/service.go @@ -85,5 +85,4 @@ func (m *Manager) BuildTCP(rootCtx context.Context, serviceName string) (tcp.Han conf.AddError(err, true) return nil, err } - } diff --git a/pkg/tls/certificate.go b/pkg/tls/certificate.go index 7f739e38b..4a43f2a2c 100644 --- a/pkg/tls/certificate.go +++ b/pkg/tls/certificate.go @@ -140,7 +140,6 @@ func (c *Certificates) isEmpty() bool { // AppendCertificate appends a Certificate to a certificates map keyed by entrypoint. func (c *Certificate) AppendCertificate(certs map[string]map[string]*tls.Certificate, ep string) error { - certContent, err := c.CertFile.Read() if err != nil { return fmt.Errorf("unable to read CertFile : %v", err) @@ -168,7 +167,6 @@ func (c *Certificate) AppendCertificate(certs map[string]map[string]*tls.Certifi SANs = append(SANs, strings.ToLower(dnsName)) } } - } if parsedCert.IPAddresses != nil { for _, ip := range parsedCert.IPAddresses { @@ -176,7 +174,6 @@ func (c *Certificate) AppendCertificate(certs map[string]map[string]*tls.Certifi SANs = append(SANs, strings.ToLower(ip.String())) } } - } certKey := strings.Join(SANs, ",") diff --git a/pkg/tls/certificate_store.go b/pkg/tls/certificate_store.go index da16472b3..4c4ac2fc2 100644 --- a/pkg/tls/certificate_store.go +++ b/pkg/tls/certificate_store.go @@ -56,7 +56,6 @@ func (c CertificateStore) getDefaultCertificateDomains() []string { // GetAllDomains return a slice with all the certificate domain func (c CertificateStore) GetAllDomains() []string { - allCerts := c.getDefaultCertificateDomains() // Get dynamic certificates diff --git a/pkg/types/logs.go b/pkg/types/logs.go index 7c9f82906..f561effc6 100644 --- a/pkg/types/logs.go +++ b/pkg/types/logs.go @@ -64,7 +64,7 @@ type FieldHeaders struct { // AccessLogFields holds configuration for access log fields type AccessLogFields struct { DefaultMode string `description:"Default mode for fields: keep | drop" json:"defaultMode,omitempty" toml:"defaultMode,omitempty" yaml:"defaultMode,omitempty" export:"true"` - Names map[string]string `json:"names,omitempty" description:"Override mode for fields" json:"names,omitempty" toml:"names,omitempty" yaml:"names,omitempty" export:"true"` + Names map[string]string `description:"Override mode for fields" json:"names,omitempty" toml:"names,omitempty" yaml:"names,omitempty" export:"true"` Headers *FieldHeaders `description:"Headers to keep, drop or redact" json:"headers,omitempty" toml:"headers,omitempty" yaml:"headers,omitempty" export:"true"` }