diff --git a/cluster/datastore.go b/cluster/datastore.go index add941aa1..081c1f5f2 100644 --- a/cluster/datastore.go +++ b/cluster/datastore.go @@ -152,7 +152,7 @@ func (d *Datastore) Begin() (Transaction, Object, error) { operation := func() error { meta := d.get() if meta.Lock != id { - return fmt.Errorf("Object lock value: expected %s, got %s", id, meta.Lock) + return fmt.Errorf("object lock value: expected %s, got %s", id, meta.Lock) } return nil } @@ -167,7 +167,7 @@ func (d *Datastore) Begin() (Transaction, Object, error) { ebo.MaxElapsedTime = 60 * time.Second err = backoff.RetryNotify(safe.OperationWithRecover(operation), ebo, notify) if err != nil { - return nil, nil, fmt.Errorf("Datastore cannot sync: %v", err) + return nil, nil, fmt.Errorf("datastore cannot sync: %v", err) } // we synced with KV store, we can now return Setter @@ -224,12 +224,12 @@ func (s *datastoreTransaction) Commit(object Object) error { s.localLock.Lock() defer s.localLock.Unlock() if s.dirty { - return fmt.Errorf("Transaction already used, please begin a new one") + return fmt.Errorf("transaction already used, please begin a new one") } s.Datastore.meta.object = object err := s.Datastore.meta.Marshall() if err != nil { - return fmt.Errorf("Marshall error: %s", err) + return fmt.Errorf("marshall error: %s", err) } err = s.kv.StoreConfig(s.Datastore.meta) if err != nil { @@ -238,7 +238,7 @@ func (s *datastoreTransaction) Commit(object Object) error { err = s.remoteLock.Unlock() if err != nil { - return fmt.Errorf("Unlock error: %s", err) + return fmt.Errorf("unlock error: %s", err) } s.dirty = true diff --git a/cmd/bug/bug.go b/cmd/bug/bug.go index efea80c94..08e00133a 100644 --- a/cmd/bug/bug.go +++ b/cmd/bug/bug.go @@ -88,7 +88,7 @@ Add more configuration information here. // NewCmd builds a new Bug command func NewCmd(traefikConfiguration *cmd.TraefikConfiguration, traefikPointersConfiguration *cmd.TraefikConfiguration) *flaeg.Command { - //version Command init + // version Command init return &flaeg.Command{ Name: "bug", Description: `Report an issue on Traefik bugtracker`, diff --git a/configuration/router/internal_router_test.go b/configuration/router/internal_router_test.go index eae7aa3b1..3c39c6c60 100644 --- a/configuration/router/internal_router_test.go +++ b/configuration/router/internal_router_test.go @@ -288,7 +288,7 @@ func TestWithMiddleware(t *testing.T) { request := httptest.NewRequest(http.MethodGet, "/test", nil) internalMuxRouter.ServeHTTP(recorder, request) - obtained := string(recorder.Body.Bytes()) + obtained := recorder.Body.String() assert.Equal(t, "before middleware1|before middleware2|router|after middleware2|after middleware1", obtained) } diff --git a/docs/configuration/backends/file.md b/docs/configuration/backends/file.md index e4a4bed2b..e85dd8a27 100644 --- a/docs/configuration/backends/file.md +++ b/docs/configuration/backends/file.md @@ -81,7 +81,7 @@ Træfik can be configured with a file. trustForwardHeader = true authResponseHeaders = ["X-Auth-User"] [frontends.frontend1.auth.forward.tls] - ca = [ "path/to/local.crt"] + ca = "path/to/local.crt" caOptional = true cert = "path/to/foo.cert" key = "path/to/foo.key" diff --git a/docs/configuration/entrypoints.md b/docs/configuration/entrypoints.md index c217d35ef..cc0f17c9b 100644 --- a/docs/configuration/entrypoints.md +++ b/docs/configuration/entrypoints.md @@ -56,7 +56,7 @@ trustForwardHeader = true authResponseHeaders = ["X-Auth-User"] [entryPoints.http.auth.forward.tls] - ca = [ "path/to/local.crt"] + ca = "path/to/local.crt" caOptional = true cert = "path/to/foo.cert" key = "path/to/foo.key" @@ -347,7 +347,7 @@ Otherwise, the response from the authentication server is returned. # Optional # [entryPoints.http.auth.forward.tls] - ca = [ "path/to/local.crt"] + ca = "path/to/local.crt" caOptional = true cert = "path/to/foo.cert" key = "path/to/foo.key" diff --git a/h2c/h2c.go b/h2c/h2c.go index d73ddeadc..70e144d2d 100644 --- a/h2c/h2c.go +++ b/h2c/h2c.go @@ -45,7 +45,6 @@ func init() { // to provide an http.Server. type Server struct { *http.Server - originalHandler http.Handler } // Serve Put a middleware around the original handler to handle h2c @@ -101,6 +100,9 @@ func initH2CWithPriorKnowledge(w http.ResponseWriter) (net.Conn, error) { buf := make([]byte, len(expectedBody)) n, err := io.ReadFull(rw, buf) + if err != nil { + return nil, fmt.Errorf("fail to read body: %v", err) + } if bytes.Equal(buf[0:n], []byte(expectedBody)) { c := &rwConn{ @@ -132,7 +134,7 @@ func drainClientPreface(r io.Reader) error { return err } if n != prefaceLen || buf.String() != http2.ClientPreface { - return fmt.Errorf("Client never sent: %s", http2.ClientPreface) + return fmt.Errorf("client never sent: %s", http2.ClientPreface) } return nil } @@ -363,7 +365,7 @@ func getH2Settings(h http.Header) ([]http2.Setting, error) { } settings, err := decodeSettings(vals[0]) if err != nil { - return nil, fmt.Errorf("Invalid HTTP2-Settings: %q", vals[0]) + return nil, fmt.Errorf("invalid HTTP2-Settings: %q", vals[0]) } return settings, nil } diff --git a/integration/basic_test.go b/integration/basic_test.go index 357fc44a1..a576cea46 100644 --- a/integration/basic_test.go +++ b/integration/basic_test.go @@ -28,7 +28,7 @@ func (s *SimpleSuite) TestInvalidConfigShouldFail(c *check.C) { actual := output.String() if !strings.Contains(actual, expected) { - return fmt.Errorf("Got %s, wanted %s", actual, expected) + return fmt.Errorf("got %s, wanted %s", actual, expected) } return nil @@ -72,7 +72,7 @@ func (s *SimpleSuite) TestDefaultEntryPoints(c *check.C) { actual := output.String() if !strings.Contains(actual, expected) { - return fmt.Errorf("Got %s, wanted %s", actual, expected) + return fmt.Errorf("got %s, wanted %s", actual, expected) } return nil @@ -93,10 +93,10 @@ func (s *SimpleSuite) TestPrintHelp(c *check.C) { actual := output.String() if strings.Contains(actual, notExpected) { - return fmt.Errorf("Got %s", actual) + return fmt.Errorf("got %s", actual) } if !strings.Contains(actual, expected) { - return fmt.Errorf("Got %s, wanted %s", actual, expected) + return fmt.Errorf("got %s, wanted %s", actual, expected) } return nil diff --git a/integration/consul_catalog_test.go b/integration/consul_catalog_test.go index e92cee66a..7607b41d8 100644 --- a/integration/consul_catalog_test.go +++ b/integration/consul_catalog_test.go @@ -501,7 +501,7 @@ func (s *ConsulCatalogSuite) TestRefreshConfigPortChange(c *check.C) { } func (s *ConsulCatalogSuite) TestRetryWithConsulServer(c *check.C) { - //Scale consul to 0 to be able to start traefik before and test retry + // Scale consul to 0 to be able to start traefik before and test retry s.composeProject.Scale(c, "consul", 0) cmd, display := s.traefikCmd( @@ -547,7 +547,7 @@ func (s *ConsulCatalogSuite) TestRetryWithConsulServer(c *check.C) { } func (s *ConsulCatalogSuite) TestServiceWithMultipleHealthCheck(c *check.C) { - //Scale consul to 0 to be able to start traefik before and test retry + // Scale consul to 0 to be able to start traefik before and test retry s.composeProject.Scale(c, "consul", 0) cmd, display := s.traefikCmd( diff --git a/integration/consul_test.go b/integration/consul_test.go index 7014e5149..a6c1c192f 100644 --- a/integration/consul_test.go +++ b/integration/consul_test.go @@ -282,7 +282,7 @@ func (s *ConsulSuite) TestGlobalConfiguration(c *check.C) { err = try.GetRequest("http://127.0.0.1:8080/api/providers", 60*time.Second, try.BodyContains("Path:/test")) c.Assert(err, checker.IsNil) - //check + // check req, err := http.NewRequest(http.MethodGet, "http://127.0.0.1:8001/", nil) c.Assert(err, checker.IsNil) req.Host = "test.localhost" @@ -469,7 +469,7 @@ func datastoreContains(datastore *cluster.Datastore, expectedValue string) func( return func() error { kvStruct := datastore.Get().(*TestStruct) if kvStruct.String != expectedValue { - return fmt.Errorf("Got %s, wanted %s", kvStruct.String, expectedValue) + return fmt.Errorf("got %s, wanted %s", kvStruct.String, expectedValue) } return nil } diff --git a/integration/docker_compose_test.go b/integration/docker_compose_test.go index cc5ab2c08..2ca65eaac 100644 --- a/integration/docker_compose_test.go +++ b/integration/docker_compose_test.go @@ -41,7 +41,7 @@ func (s *DockerComposeSuite) TestComposeScale(c *check.C) { s.composeProject.Scale(c, composeService, serviceCount) - file := s.adaptFileForHost(c, "fixtures/docker/simple.toml") + file := s.adaptFileForHost(c, "fixtures/docker/minimal.toml") defer os.Remove(file) cmd, display := s.traefikCmd(withConfigFile(file)) diff --git a/integration/error_pages_test.go b/integration/error_pages_test.go index d97facc8e..b25c81ad9 100644 --- a/integration/error_pages_test.go +++ b/integration/error_pages_test.go @@ -49,7 +49,7 @@ func (s *ErrorPagesSuite) TestSimpleConfiguration(c *check.C) { func (s *ErrorPagesSuite) TestErrorPage(c *check.C) { - //error.toml contains a mis-configuration of the backend host + // error.toml contains a mis-configuration of the backend host file := s.adaptFile(c, "fixtures/error_pages/error.toml", struct { Server1 string Server2 string diff --git a/integration/etcd3_test.go b/integration/etcd3_test.go index 0d01d861e..00dc755ed 100644 --- a/integration/etcd3_test.go +++ b/integration/etcd3_test.go @@ -280,7 +280,7 @@ func (s *Etcd3Suite) TestGlobalConfiguration(c *check.C) { err = try.GetRequest("http://127.0.0.1:8080/api/providers", 60*time.Second, try.BodyContains("Path:/test")) c.Assert(err, checker.IsNil) - //check + // check req, err := http.NewRequest(http.MethodGet, "http://127.0.0.1:8001/", nil) c.Assert(err, checker.IsNil) req.Host = "test.localhost" @@ -298,7 +298,7 @@ func (s *Etcd3Suite) TestCertificatesContentWithSNIConfigHandshake(c *check.C) { "--etcd.useAPIV3=true") defer display(c) - //Copy the contents of the certificate files into ETCD + // Copy the contents of the certificate files into ETCD snitestComCert, err := ioutil.ReadFile("fixtures/https/snitest.com.cert") c.Assert(err, checker.IsNil) snitestComKey, err := ioutil.ReadFile("fixtures/https/snitest.com.key") @@ -376,7 +376,7 @@ func (s *Etcd3Suite) TestCertificatesContentWithSNIConfigHandshake(c *check.C) { err = try.GetRequest("http://127.0.0.1:8080/api/providers", 60*time.Second, try.BodyContains("Host:snitest.org")) c.Assert(err, checker.IsNil) - //check + // check tlsConfig := &tls.Config{ InsecureSkipVerify: true, ServerName: "snitest.com", @@ -406,7 +406,7 @@ func (s *Etcd3Suite) TestCommandStoreConfig(c *check.C) { // wait for traefik finish without error cmd.Wait() - //CHECK + // CHECK checkmap := map[string]string{ "/traefik/loglevel": "DEBUG", "/traefik/defaultentrypoints/0": "http", diff --git a/integration/fixtures/docker/minimal.toml b/integration/fixtures/docker/minimal.toml new file mode 100644 index 000000000..7a8cd9ffa --- /dev/null +++ b/integration/fixtures/docker/minimal.toml @@ -0,0 +1,14 @@ +defaultEntryPoints = ["http"] + +logLevel = "DEBUG" + +[entryPoints] + [entryPoints.http] + address = ":8000" + +[api] + +[docker] +endpoint = "{{.DockerHost}}" +domain = "docker.localhost" +exposedByDefault = false diff --git a/integration/fixtures/docker/simple.toml b/integration/fixtures/docker/simple.toml index cc668ba07..f51e491b9 100644 --- a/integration/fixtures/docker/simple.toml +++ b/integration/fixtures/docker/simple.toml @@ -9,9 +9,6 @@ logLevel = "DEBUG" [api] [docker] - -# It's dynamagic ! endpoint = "{{.DockerHost}}" - domain = "docker.localhost" exposedByDefault = true diff --git a/integration/healthcheck_test.go b/integration/healthcheck_test.go index c1126eb45..7f1802525 100644 --- a/integration/healthcheck_test.go +++ b/integration/healthcheck_test.go @@ -194,7 +194,7 @@ func (s *HealthCheckSuite) TestPortOverload(c *check.C) { c.Assert(err, checker.IsNil) frontendHealthReq.Host = "test.localhost" - //We test bad gateway because we use an invalid port for the backend + // We test bad gateway because we use an invalid port for the backend err = try.Request(frontendHealthReq, 500*time.Millisecond, try.StatusCodeIs(http.StatusBadGateway)) c.Assert(err, checker.IsNil) diff --git a/integration/log_rotation_test.go b/integration/log_rotation_test.go index 86d4466c7..f436f723d 100644 --- a/integration/log_rotation_test.go +++ b/integration/log_rotation_test.go @@ -123,7 +123,7 @@ func (s *LogRotationSuite) TestTraefikLogRotation(c *check.C) { // If more log entries are output on startup c.Assert(lineCount, checker.GreaterOrEqualThan, 5) - //Verify traefik.log output as expected + // Verify traefik.log output as expected lineCount = verifyLogLines(c, traefikTestLogFile, lineCount, false) c.Assert(lineCount, checker.GreaterOrEqualThan, 7) } diff --git a/integration/marathon_test.go b/integration/marathon_test.go index 57dee52f2..aea3809d2 100644 --- a/integration/marathon_test.go +++ b/integration/marathon_test.go @@ -8,7 +8,7 @@ import ( "github.com/containous/traefik/integration/try" "github.com/containous/traefik/provider/label" - marathon "github.com/gambol99/go-marathon" + "github.com/gambol99/go-marathon" "github.com/go-check/check" checker "github.com/vdemeester/shakers" ) diff --git a/integration/resources/compose/minimal.yml b/integration/resources/compose/minimal.yml index 8490e59a7..4c8d187cd 100644 --- a/integration/resources/compose/minimal.yml +++ b/integration/resources/compose/minimal.yml @@ -2,3 +2,4 @@ whoami1: image: emilevauge/whoami labels: - traefik.frontend.rule=PathPrefix:/whoami + - traefik.enable=true \ No newline at end of file diff --git a/integration/try/condition.go b/integration/try/condition.go index e7ee9c9d2..999b6256e 100644 --- a/integration/try/condition.go +++ b/integration/try/condition.go @@ -82,7 +82,7 @@ func HasBody() ResponseCondition { } if len(body) == 0 { - return errors.New("Response doesn't have body content") + return errors.New("response doesn't have body content") } return nil } diff --git a/integration/websocket_test.go b/integration/websocket_test.go index 509d9cc33..f06583bfb 100644 --- a/integration/websocket_test.go +++ b/integration/websocket_test.go @@ -279,7 +279,7 @@ func (s *WebsocketSuite) TestSSLTermination(c *check.C) { err = try.GetRequest("http://127.0.0.1:8080/api/providers", 10*time.Second, try.BodyContains("127.0.0.1")) c.Assert(err, checker.IsNil) - //Add client self-signed cert + // Add client self-signed cert roots := x509.NewCertPool() certContent, err := ioutil.ReadFile("./resources/tls/local.cert") c.Assert(err, checker.IsNil) @@ -487,7 +487,7 @@ func (s *WebsocketSuite) TestSSLhttp2(c *check.C) { err = try.GetRequest("http://127.0.0.1:8080/api/providers", 10*time.Second, try.BodyContains("127.0.0.1")) c.Assert(err, checker.IsNil) - //Add client self-signed cert + // Add client self-signed cert roots := x509.NewCertPool() certContent, err := ioutil.ReadFile("./resources/tls/local.cert") c.Assert(err, checker.IsNil) diff --git a/metrics/influxdb.go b/metrics/influxdb.go index 6f777a986..ea5f92b88 100644 --- a/metrics/influxdb.go +++ b/metrics/influxdb.go @@ -154,17 +154,16 @@ func (w *influxDBWriter) Write(bp influxdb.BatchPoints) error { return nil } -func (w *influxDBWriter) initWriteClient() (c influxdb.Client, err error) { +func (w *influxDBWriter) initWriteClient() (influxdb.Client, error) { if w.config.Protocol == "http" { - c, err = influxdb.NewHTTPClient(influxdb.HTTPConfig{ - Addr: w.config.Address, - }) - } else { - c, err = influxdb.NewUDPClient(influxdb.UDPConfig{ + return influxdb.NewHTTPClient(influxdb.HTTPConfig{ Addr: w.config.Address, }) } - return + + return influxdb.NewUDPClient(influxdb.UDPConfig{ + Addr: w.config.Address, + }) } func (w *influxDBWriter) handleWriteError(c influxdb.Client, writeErr error) error { diff --git a/metrics/metrics.go b/metrics/metrics.go index 62079d16a..a233ec791 100644 --- a/metrics/metrics.go +++ b/metrics/metrics.go @@ -9,6 +9,7 @@ import ( type Registry interface { // IsEnabled shows whether metrics instrumentation is enabled. IsEnabled() bool + // server metrics ConfigReloadsCounter() metrics.Counter ConfigReloadsFailureCounter() metrics.Counter @@ -38,18 +39,18 @@ func NewVoidRegistry() Registry { // It handles the case when a registry hasn't registered some metric and returns nil. // This allows for feature imparity between the different metric implementations. func NewMultiRegistry(registries []Registry) Registry { - configReloadsCounter := []metrics.Counter{} - configReloadsFailureCounter := []metrics.Counter{} - lastConfigReloadSuccessGauge := []metrics.Gauge{} - lastConfigReloadFailureGauge := []metrics.Gauge{} - entrypointReqsCounter := []metrics.Counter{} - entrypointReqDurationHistogram := []metrics.Histogram{} - entrypointOpenConnsGauge := []metrics.Gauge{} - backendReqsCounter := []metrics.Counter{} - backendReqDurationHistogram := []metrics.Histogram{} - backendOpenConnsGauge := []metrics.Gauge{} - backendRetriesCounter := []metrics.Counter{} - backendServerUpGauge := []metrics.Gauge{} + var configReloadsCounter []metrics.Counter + var configReloadsFailureCounter []metrics.Counter + var lastConfigReloadSuccessGauge []metrics.Gauge + var lastConfigReloadFailureGauge []metrics.Gauge + var entrypointReqsCounter []metrics.Counter + var entrypointReqDurationHistogram []metrics.Histogram + var entrypointOpenConnsGauge []metrics.Gauge + var backendReqsCounter []metrics.Counter + var backendReqDurationHistogram []metrics.Histogram + var backendOpenConnsGauge []metrics.Gauge + var backendRetriesCounter []metrics.Counter + var backendServerUpGauge []metrics.Gauge for _, r := range registries { if r.ConfigReloadsCounter() != nil { diff --git a/middlewares/accesslog/capture_response_writer.go b/middlewares/accesslog/capture_response_writer.go index 6ade37b3e..0892b3980 100644 --- a/middlewares/accesslog/capture_response_writer.go +++ b/middlewares/accesslog/capture_response_writer.go @@ -49,7 +49,7 @@ func (crw *captureResponseWriter) Hijack() (net.Conn, *bufio.ReadWriter, error) if h, ok := crw.rw.(http.Hijacker); ok { return h.Hijack() } - return nil, nil, fmt.Errorf("Not a hijacker: %T", crw.rw) + return nil, nil, fmt.Errorf("not a hijacker: %T", crw.rw) } func (crw *captureResponseWriter) CloseNotify() <-chan bool { diff --git a/middlewares/auth/authenticator_test.go b/middlewares/auth/authenticator_test.go index 3b90fbe57..0de79dfb2 100644 --- a/middlewares/auth/authenticator_test.go +++ b/middlewares/auth/authenticator_test.go @@ -72,7 +72,7 @@ func TestBasicAuthFail(t *testing.T) { Users: []string{"test"}, }, }, &tracing.Tracing{}) - assert.Contains(t, err.Error(), "Error parsing Authenticator user", "should contains") + assert.Contains(t, err.Error(), "error parsing Authenticator user", "should contains") authMiddleware, err := NewAuthenticator(&types.Auth{ Basic: &types.Basic{ @@ -131,7 +131,7 @@ func TestDigestAuthFail(t *testing.T) { Users: []string{"test"}, }, }, &tracing.Tracing{}) - assert.Contains(t, err.Error(), "Error parsing Authenticator user", "should contains") + assert.Contains(t, err.Error(), "error parsing Authenticator user", "should contains") authMiddleware, err := NewAuthenticator(&types.Auth{ Digest: &types.Digest{ diff --git a/middlewares/auth/parser.go b/middlewares/auth/parser.go index 9bf82e4a7..61492a99f 100644 --- a/middlewares/auth/parser.go +++ b/middlewares/auth/parser.go @@ -20,7 +20,7 @@ func parserBasicUsers(basic *types.Basic) (map[string]string, error) { for _, user := range userStrs { split := strings.Split(user, ":") if len(split) != 2 { - return nil, fmt.Errorf("Error parsing Authenticator user: %v", user) + return nil, fmt.Errorf("error parsing Authenticator user: %v", user) } userMap[split[0]] = split[1] } @@ -40,7 +40,7 @@ func parserDigestUsers(digest *types.Digest) (map[string]string, error) { for _, user := range userStrs { split := strings.Split(user, ":") if len(split) != 3 { - return nil, fmt.Errorf("Error parsing Authenticator user: %v", user) + return nil, fmt.Errorf("error parsing Authenticator user: %v", user) } userMap[split[0]+":"+split[1]] = split[2] } diff --git a/middlewares/compress.go b/middlewares/compress.go index 4f1fb751d..e10413dfa 100644 --- a/middlewares/compress.go +++ b/middlewares/compress.go @@ -12,7 +12,7 @@ import ( // Compress is a middleware that allows redirection type Compress struct{} -// ServerHTTP is a function used by Negroni +// ServeHTTP is a function used by Negroni func (c *Compress) ServeHTTP(rw http.ResponseWriter, r *http.Request, next http.HandlerFunc) { contentType := r.Header.Get("Content-Type") if strings.HasPrefix(contentType, "application/grpc") { diff --git a/middlewares/routes.go b/middlewares/routes.go index 4f017fce0..86be13c0c 100644 --- a/middlewares/routes.go +++ b/middlewares/routes.go @@ -21,8 +21,8 @@ func NewRoutes(router *mux.Router) *Routes { func (router *Routes) ServeHTTP(rw http.ResponseWriter, r *http.Request, next http.HandlerFunc) { routeMatch := mux.RouteMatch{} if router.router.Match(r, &routeMatch) { - json, _ := json.Marshal(routeMatch.Handler) - log.Println("Request match route ", json) + rt, _ := json.Marshal(routeMatch.Handler) + log.Println("Request match route ", rt) } next(rw, r) } diff --git a/middlewares/tracing/zipkin/zipkin.go b/middlewares/tracing/zipkin/zipkin.go index 2a884810c..cb4b88c15 100644 --- a/middlewares/tracing/zipkin/zipkin.go +++ b/middlewares/tracing/zipkin/zipkin.go @@ -4,7 +4,7 @@ import ( "io" "github.com/containous/traefik/log" - opentracing "github.com/opentracing/opentracing-go" + "github.com/opentracing/opentracing-go" zipkin "github.com/openzipkin/zipkin-go-opentracing" ) diff --git a/provider/docker/docker_unix.go b/provider/docker/docker_unix.go index cfb97121b..347b16710 100644 --- a/provider/docker/docker_unix.go +++ b/provider/docker/docker_unix.go @@ -4,5 +4,5 @@ package docker const ( // DockerAPIVersion is a constant holding the version of the Provider API traefik will use - DockerAPIVersion string = "1.21" + DockerAPIVersion = "1.21" ) diff --git a/provider/ecs/config_test.go b/provider/ecs/config_test.go index 26ba8931a..ad132871a 100644 --- a/provider/ecs/config_test.go +++ b/provider/ecs/config_test.go @@ -496,87 +496,6 @@ func TestFilterInstance(t *testing.T) { } } -func TestChunkedTaskArns(t *testing.T) { - testVal := "a" - testCases := []struct { - desc string - count int - expectedLengths []int - }{ - { - desc: "0 parameter should return nil", - count: 0, - expectedLengths: []int(nil), - }, - { - desc: "1 parameter should return 1 array of 1 element", - count: 1, - expectedLengths: []int{1}, - }, - { - desc: "99 parameters should return 1 array of 99 elements", - count: 99, - expectedLengths: []int{99}, - }, - { - desc: "100 parameters should return 1 array of 100 elements", - count: 100, - expectedLengths: []int{100}, - }, - { - desc: "101 parameters should return 1 array of 100 elements and 1 array of 1 element", - count: 101, - expectedLengths: []int{100, 1}, - }, - { - desc: "199 parameters should return 1 array of 100 elements and 1 array of 99 elements", - count: 199, - expectedLengths: []int{100, 99}, - }, - { - desc: "200 parameters should return 2 arrays of 100 elements each", - count: 200, - expectedLengths: []int{100, 100}, - }, - { - desc: "201 parameters should return 2 arrays of 100 elements each and 1 array of 1 element", - count: 201, - expectedLengths: []int{100, 100, 1}, - }, - { - desc: "555 parameters should return 5 arrays of 100 elements each and 1 array of 55 elements", - count: 555, - expectedLengths: []int{100, 100, 100, 100, 100, 55}, - }, - { - desc: "1001 parameters should return 10 arrays of 100 elements each and 1 array of 1 element", - count: 1001, - expectedLengths: []int{100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 1}, - }, - } - - for _, test := range testCases { - test := test - t.Run(test.desc, func(t *testing.T) { - t.Parallel() - - var tasks []*string - for v := 0; v < test.count; v++ { - tasks = append(tasks, &testVal) - } - - out := chunkedTaskArns(tasks) - var outCount []int - - for _, el := range out { - outCount = append(outCount, len(el)) - } - - assert.Equal(t, test.expectedLengths, outCount, "Chunking %d elements", test.count) - }) - } -} - func TestGetHost(t *testing.T) { testCases := []struct { desc string diff --git a/provider/ecs/ecs.go b/provider/ecs/ecs.go index 9de574c5f..78c157835 100644 --- a/provider/ecs/ecs.go +++ b/provider/ecs/ecs.go @@ -227,7 +227,7 @@ func (p *Provider) listInstances(ctx context.Context, client *awsClient) ([]ecsI Cluster: &c, }) if err != nil { - log.Errorf("Unable to describe tasks for %s", page.TaskArns) + log.Errorf("Unable to describe tasks for %v", page.TaskArns) } else { for _, t := range resp.Tasks { tasks[aws.StringValue(t.TaskArn)] = t @@ -396,19 +396,3 @@ func (p *Provider) loadECSConfig(ctx context.Context, client *awsClient) (*types return p.buildConfiguration(instances) } - -// Provider expects no more than 100 parameters be passed to a DescribeTask call; thus, pack -// each string into an array capped at 100 elements -func chunkedTaskArns(tasks []*string) [][]*string { - var chunkedTasks [][]*string - for i := 0; i < len(tasks); i += 100 { - var sliceEnd int - if i+100 < len(tasks) { - sliceEnd = i + 100 - } else { - sliceEnd = len(tasks) - } - chunkedTasks = append(chunkedTasks, tasks[i:sliceEnd]) - } - return chunkedTasks -} diff --git a/provider/kubernetes/kubernetes_test.go b/provider/kubernetes/kubernetes_test.go index 6c9a752f2..1b6a0afa8 100644 --- a/provider/kubernetes/kubernetes_test.go +++ b/provider/kubernetes/kubernetes_test.go @@ -2165,7 +2165,7 @@ func TestTLSSecretLoad(t *testing.T) { }, }, } - endpoints := []*corev1.Endpoints{} + var endpoints []*corev1.Endpoints watchChan := make(chan interface{}) client := clientMock{ ingresses: ingresses, diff --git a/provider/kubernetes/namespace.go b/provider/kubernetes/namespace.go index b5bb0ec42..0b1f9a434 100644 --- a/provider/kubernetes/namespace.go +++ b/provider/kubernetes/namespace.go @@ -8,8 +8,8 @@ import ( // Namespaces holds kubernetes namespaces type Namespaces []string -//Set adds strings elem into the the parser -//it splits str on , and ; +// Set adds strings elem into the the parser +// it splits str on , and ; func (ns *Namespaces) Set(str string) error { fargs := func(c rune) bool { return c == ',' || c == ';' @@ -20,13 +20,13 @@ func (ns *Namespaces) Set(str string) error { return nil } -//Get []string +// Get []string func (ns *Namespaces) Get() interface{} { return *ns } -//String return slice in a string +// String return slice in a string func (ns *Namespaces) String() string { return fmt.Sprintf("%v", *ns) } -//SetValue sets []string into the parser +// SetValue sets []string into the parser func (ns *Namespaces) SetValue(val interface{}) { *ns = val.(Namespaces) } diff --git a/provider/label/label.go b/provider/label/label.go index 87bf950f8..b8f03c855 100644 --- a/provider/label/label.go +++ b/provider/label/label.go @@ -30,15 +30,9 @@ const ( ) var ( - // RegexpBaseFrontendErrorPage used to extract error pages from service's label - RegexpBaseFrontendErrorPage = regexp.MustCompile(`^frontend\.errors\.(?P[^ .]+)\.(?P[^ .]+)$`) - // RegexpFrontendErrorPage used to extract error pages from label RegexpFrontendErrorPage = regexp.MustCompile(`^traefik\.frontend\.errors\.(?P[^ .]+)\.(?P[^ .]+)$`) - // RegexpBaseFrontendRateLimit used to extract rate limits from service's label - RegexpBaseFrontendRateLimit = regexp.MustCompile(`^frontend\.rateLimit\.rateSet\.(?P[^ .]+)\.(?P[^ .]+)$`) - // RegexpFrontendRateLimit used to extract rate limits from label RegexpFrontendRateLimit = regexp.MustCompile(`^traefik\.frontend\.rateLimit\.rateSet\.(?P[^ .]+)\.(?P[^ .]+)$`) ) diff --git a/provider/marathon/readiness.go b/provider/marathon/readiness.go index d504e9d05..63b7fbfe3 100644 --- a/provider/marathon/readiness.go +++ b/provider/marathon/readiness.go @@ -4,7 +4,7 @@ import ( "time" "github.com/containous/traefik/log" - marathon "github.com/gambol99/go-marathon" + "github.com/gambol99/go-marathon" ) const ( diff --git a/provider/mesos/mesos.go b/provider/mesos/mesos.go index cfcab83b7..0428d71bc 100644 --- a/provider/mesos/mesos.go +++ b/provider/mesos/mesos.go @@ -24,7 +24,7 @@ import ( var _ provider.Provider = (*Provider)(nil) -//Provider holds configuration of the provider. +// Provider holds configuration of the provider. type Provider struct { provider.BaseProvider Endpoint string `description:"Mesos server endpoint. You can also specify multiple endpoint for Mesos"` diff --git a/provider/mesos/mesos_helper_test.go b/provider/mesos/mesos_helper_test.go index 3dccae789..4fd04f941 100644 --- a/provider/mesos/mesos_helper_test.go +++ b/provider/mesos/mesos_helper_test.go @@ -37,7 +37,7 @@ func TestBuilder(t *testing.T) { DiscoveryInfo: state.DiscoveryInfo{ Name: "name1", Labels: struct { - Labels []state.Label "json:\"labels\"" + Labels []state.Label `json:"labels"` }{}, Ports: state.Ports{DiscoveryPorts: []state.DiscoveryPort{ {Protocol: "TCP", Number: 80, Name: "p"}, @@ -63,7 +63,7 @@ func aTaskData(id, segment string, ops ...func(*state.Task)) taskData { } func segmentedTaskData(segments []string, ts state.Task) []taskData { - td := []taskData{} + var td []taskData lbls := label.ExtractTraefikLabels(extractLabels(ts)) for _, s := range segments { if l, ok := lbls[s]; !ok { diff --git a/safe/routine.go b/safe/routine.go index 897684e40..bb2f4fec8 100644 --- a/safe/routine.go +++ b/safe/routine.go @@ -46,14 +46,14 @@ func (p *Pool) Ctx() context.Context { return p.baseCtx } -//AddGoCtx adds a recoverable goroutine with a context without starting it +// AddGoCtx adds a recoverable goroutine with a context without starting it func (p *Pool) AddGoCtx(goroutine routineCtx) { p.lock.Lock() p.routinesCtx = append(p.routinesCtx, goroutine) p.lock.Unlock() } -//GoCtx starts a recoverable goroutine with a context +// GoCtx starts a recoverable goroutine with a context func (p *Pool) GoCtx(goroutine routineCtx) { p.lock.Lock() p.routinesCtx = append(p.routinesCtx, goroutine) @@ -154,7 +154,7 @@ func OperationWithRecover(operation backoff.Operation) backoff.Operation { defer func() { if res := recover(); res != nil { defaultRecoverGoroutine(res) - err = fmt.Errorf("Panic in operation: %s", err) + err = fmt.Errorf("panic in operation: %s", err) } }() return operation()