From cfcd4b59927d595eb51317ecf46795894b8800e9 Mon Sep 17 00:00:00 2001 From: David Christofas Date: Fri, 26 Feb 2021 14:24:25 +0100 Subject: [PATCH] resolve linter issues --- proxy/.golangci.yaml | 33 ----------------------- proxy/pkg/metrics/metrics.go | 22 +++++++++------ proxy/pkg/middleware/oidc_auth.go | 2 +- proxy/pkg/proxy/proxy_integration_test.go | 9 ++++--- proxy/pkg/server/debug/server.go | 8 ++++-- proxy/pkg/server/http/server.go | 4 ++- 6 files changed, 29 insertions(+), 49 deletions(-) delete mode 100644 proxy/.golangci.yaml diff --git a/proxy/.golangci.yaml b/proxy/.golangci.yaml deleted file mode 100644 index 64b10facf..000000000 --- a/proxy/.golangci.yaml +++ /dev/null @@ -1,33 +0,0 @@ -issues: - exclude-rules: - - path: pkg/middleware/account_uuid.go - text: "SA4006:" - linters: - - staticcheck - - path: pkg/proxy/proxy_integration_test.go - linters: - - bodyclose -linters: - enable: - - bodyclose - - deadcode - - gosimple - - govet - - staticcheck - - structcheck - - typecheck - - unused - - varcheck - - depguard - - golint - - unconvert - # - scopelint - - maligned - - misspell - - prealloc - #- gosec - - disable: - - errcheck - - ineffassign - - scopelint diff --git a/proxy/pkg/metrics/metrics.go b/proxy/pkg/metrics/metrics.go index f31cc8a78..068bfc7a0 100644 --- a/proxy/pkg/metrics/metrics.go +++ b/proxy/pkg/metrics/metrics.go @@ -49,21 +49,27 @@ func New() *Metrics { }, []string{"versions"}), } - prometheus.Register( + mustNotFail(prometheus.Register( m.Counter, - ) + )) - prometheus.Register( + mustNotFail(prometheus.Register( m.Latency, - ) + )) - prometheus.Register( + mustNotFail(prometheus.Register( m.Duration, - ) + )) - prometheus.Register( + mustNotFail(prometheus.Register( m.BuildInfo, - ) + )) return m } + +func mustNotFail(err error) { + if err != nil { + panic(err) + } +} diff --git a/proxy/pkg/middleware/oidc_auth.go b/proxy/pkg/middleware/oidc_auth.go index f2b78bbc8..e4177060c 100644 --- a/proxy/pkg/middleware/oidc_auth.go +++ b/proxy/pkg/middleware/oidc_auth.go @@ -112,7 +112,7 @@ func (m oidcAuth) getClaims(token string, req *http.Request) (claims oidc.Standa return } - var ok = false + var ok bool if claims, ok = hit.V.(oidc.StandardClaims); !ok { status = http.StatusInternalServerError return diff --git a/proxy/pkg/proxy/proxy_integration_test.go b/proxy/pkg/proxy/proxy_integration_test.go index d4ff29aec..7c357e26f 100644 --- a/proxy/pkg/proxy/proxy_integration_test.go +++ b/proxy/pkg/proxy/proxy_integration_test.go @@ -136,16 +136,17 @@ func TestProxyIntegration(t *testing.T) { rr := httptest.NewRecorder() rp.ServeHTTP(rr, tc.input) + rsp := rr.Result() - if rr.Result().StatusCode != 200 { - t.Errorf("Expected status 200 from proxy-response got %v", rr.Result().StatusCode) + if rsp.StatusCode != 200 { + t.Errorf("Expected status 200 from proxy-response got %v", rsp.StatusCode) } - resultBody, err := ioutil.ReadAll(rr.Result().Body) + resultBody, err := ioutil.ReadAll(rsp.Body) if err != nil { t.Fatal("Error reading result body") } - if err = rr.Result().Body.Close(); err != nil { + if err = rsp.Body.Close(); err != nil { t.Fatal("Error closing result body") } diff --git a/proxy/pkg/server/debug/server.go b/proxy/pkg/server/debug/server.go index 4892cdfdc..2d8bfb738 100644 --- a/proxy/pkg/server/debug/server.go +++ b/proxy/pkg/server/debug/server.go @@ -33,7 +33,9 @@ func health(cfg *config.Config) func(http.ResponseWriter, *http.Request) { // TODO(tboerger): check if services are up and running - io.WriteString(w, http.StatusText(http.StatusOK)) + if _, err := io.WriteString(w, http.StatusText(http.StatusOK)); err != nil { + panic(err) + } } } @@ -45,6 +47,8 @@ func ready(cfg *config.Config) func(http.ResponseWriter, *http.Request) { // TODO(tboerger): check if services are up and running - io.WriteString(w, http.StatusText(http.StatusOK)) + if _, err := io.WriteString(w, http.StatusText(http.StatusOK)); err != nil { + panic(err) + } } } diff --git a/proxy/pkg/server/http/server.go b/proxy/pkg/server/http/server.go index 05b0efa67..1849657d2 100644 --- a/proxy/pkg/server/http/server.go +++ b/proxy/pkg/server/http/server.go @@ -59,7 +59,9 @@ func Server(opts ...Option) (svc.Service, error) { svc.Flags(options.Flags...), ) - micro.RegisterHandler(service.Server(), chain) + if err := micro.RegisterHandler(service.Server(), chain); err != nil { + return svc.Service{}, err + } service.Init() return service, nil