diff --git a/.circleci/config.yml b/.circleci/config.yml index 511c36409a..178115dcfe 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -9,10 +9,8 @@ jobs: steps: - checkout - run: make test - + - run: make vet # TODO add these checks to the Makefile # - run: go get -v -t -d ./... # - run: go get honnef.co/go/tools/cmd/megacheck - # - run: go vet -v ./... - # - run: go test -v ./... # - run: megacheck ./... diff --git a/Makefile b/Makefile index bede5fa42e..ff6249b279 100644 --- a/Makefile +++ b/Makefile @@ -16,6 +16,7 @@ GO_ARGS=-tags '$(GO_TAGS)' export GO_BUILD=go build $(GO_ARGS) export GO_TEST=go test $(GO_ARGS) export GO_GENERATE=go generate $(GO_ARGS) +export GO_VET= go vet $(GO_ARGS) # All go source files @@ -87,6 +88,9 @@ test: all test-race: all $(GO_TEST) -race ./... +vet: all + $(GO_VET) -v ./... + bench: all $(GO_TEST) -bench=. -run=^$$ ./... diff --git a/http/auth_service.go b/http/auth_service.go index 50a8f90585..d4b81883aa 100644 --- a/http/auth_service.go +++ b/http/auth_service.go @@ -4,14 +4,14 @@ import ( "bytes" "context" "encoding/json" - "fmt" + "errors" "net/http" "path" "go.uber.org/zap" "github.com/influxdata/platform" - "github.com/influxdata/platform/kit/errors" + kerrors "github.com/influxdata/platform/kit/errors" "github.com/julienschmidt/httprouter" ) @@ -43,7 +43,7 @@ func (h *AuthorizationHandler) handlePostAuthorization(w http.ResponseWriter, r req, err := decodePostAuthorizationRequest(ctx, r) if err != nil { h.Logger.Info("failed to decode request", zap.String("handler", "postAuthorization"), zap.Error(err)) - errors.EncodeHTTP(ctx, err, w) + kerrors.EncodeHTTP(ctx, err, w) return } @@ -51,13 +51,13 @@ func (h *AuthorizationHandler) handlePostAuthorization(w http.ResponseWriter, r if err := h.AuthorizationService.CreateAuthorization(ctx, req.Authorization); err != nil { // Don't log here, it should already be handled by the service - errors.EncodeHTTP(ctx, err, w) + kerrors.EncodeHTTP(ctx, err, w) return } if err := encodeResponse(ctx, w, http.StatusCreated, req.Authorization); err != nil { h.Logger.Info("failed to encode response", zap.String("handler", "postAuthorization"), zap.Error(err)) - errors.EncodeHTTP(ctx, err, w) + kerrors.EncodeHTTP(ctx, err, w) return } } @@ -84,20 +84,20 @@ func (h *AuthorizationHandler) handleGetAuthorizations(w http.ResponseWriter, r req, err := decodeGetAuthorizationsRequest(ctx, r) if err != nil { h.Logger.Info("failed to decode request", zap.String("handler", "getAuthorizations"), zap.Error(err)) - errors.EncodeHTTP(ctx, err, w) + kerrors.EncodeHTTP(ctx, err, w) return } as, _, err := h.AuthorizationService.FindAuthorizations(ctx, req.filter) if err != nil { // Don't log here, it should already be handled by the service - errors.EncodeHTTP(ctx, err, w) + kerrors.EncodeHTTP(ctx, err, w) return } if err := encodeResponse(ctx, w, http.StatusOK, as); err != nil { h.Logger.Info("failed to encode response", zap.String("handler", "getAuthorizations"), zap.Error(err)) - errors.EncodeHTTP(ctx, err, w) + kerrors.EncodeHTTP(ctx, err, w) return } } @@ -142,20 +142,20 @@ func (h *AuthorizationHandler) handleGetAuthorization(w http.ResponseWriter, r * req, err := decodeGetAuthorizationRequest(ctx, r) if err != nil { h.Logger.Info("failed to decode request", zap.String("handler", "getAuthorization"), zap.Error(err)) - errors.EncodeHTTP(ctx, err, w) + kerrors.EncodeHTTP(ctx, err, w) return } a, err := h.AuthorizationService.FindAuthorizationByID(ctx, req.ID) if err != nil { // Don't log here, it should already be handled by the service - errors.EncodeHTTP(ctx, err, w) + kerrors.EncodeHTTP(ctx, err, w) return } if err := encodeResponse(ctx, w, http.StatusOK, a); err != nil { h.Logger.Info("failed to encode response", zap.String("handler", "getAuthorization"), zap.Error(err)) - errors.EncodeHTTP(ctx, err, w) + kerrors.EncodeHTTP(ctx, err, w) return } } @@ -168,7 +168,7 @@ func decodeGetAuthorizationRequest(ctx context.Context, r *http.Request) (*getAu params := httprouter.ParamsFromContext(ctx) id := params.ByName("id") if id == "" { - return nil, errors.InvalidDataf("url missing id") + return nil, kerrors.InvalidDataf("url missing id") } var i platform.ID @@ -188,13 +188,13 @@ func (h *AuthorizationHandler) handleDeleteAuthorization(w http.ResponseWriter, req, err := decodeDeleteAuthorizationRequest(ctx, r) if err != nil { h.Logger.Info("failed to decode request", zap.String("handler", "deleteAuthorization"), zap.Error(err)) - errors.EncodeHTTP(ctx, err, w) + kerrors.EncodeHTTP(ctx, err, w) return } if err := h.AuthorizationService.DeleteAuthorization(ctx, req.ID); err != nil { // Don't log here, it should already be handled by the service - errors.EncodeHTTP(ctx, err, w) + kerrors.EncodeHTTP(ctx, err, w) return } @@ -209,7 +209,7 @@ func decodeDeleteAuthorizationRequest(ctx context.Context, r *http.Request) (*de params := httprouter.ParamsFromContext(ctx) id := params.ByName("id") if id == "" { - return nil, errors.InvalidDataf("url missing id") + return nil, kerrors.InvalidDataf("url missing id") } var i platform.ID @@ -250,7 +250,7 @@ func (s *AuthorizationService) FindAuthorizationByID(ctx context.Context, id pla } if resp.StatusCode != http.StatusOK { - return nil, fmt.Errorf(resp.Header.Get("X-Influx-Error")) + return nil, errors.New(resp.Header.Get("X-Influx-Error")) } var b platform.Authorization @@ -264,7 +264,7 @@ func (s *AuthorizationService) FindAuthorizationByID(ctx context.Context, id pla // FindAuthorizationByToken returns a single authorization by Token. func (s *AuthorizationService) FindAuthorizationByToken(ctx context.Context, token string) (*platform.Authorization, error) { - return nil, fmt.Errorf("not supported in HTTP authorization service") + return nil, errors.New("not supported in HTTP authorization service") } // FindAuthorizations returns a list of authorizations that match filter and the total count of matching authorizations. @@ -304,7 +304,7 @@ func (s *AuthorizationService) FindAuthorizations(ctx context.Context, filter pl } if resp.StatusCode != http.StatusOK { - return nil, 0, fmt.Errorf(resp.Header.Get("X-Influx-Error")) + return nil, 0, errors.New(resp.Header.Get("X-Influx-Error")) } var bs []*platform.Authorization @@ -349,7 +349,7 @@ func (s *AuthorizationService) CreateAuthorization(ctx context.Context, a *platf // TODO: this should really check the error from the headers if resp.StatusCode != http.StatusCreated { - return fmt.Errorf(resp.Header.Get("X-Influx-Error")) + return errors.New(resp.Header.Get("X-Influx-Error")) } if err := json.NewDecoder(resp.Body).Decode(a); err != nil { @@ -383,7 +383,7 @@ func (s *AuthorizationService) DeleteAuthorization(ctx context.Context, id platf return nil } - return fmt.Errorf(resp.Header.Get("X-Influx-Error")) + return errors.New(resp.Header.Get("X-Influx-Error")) } func authorizationIDPath(id platform.ID) string { diff --git a/http/bucket_service.go b/http/bucket_service.go index 67577892b0..ef5e47b143 100644 --- a/http/bucket_service.go +++ b/http/bucket_service.go @@ -4,12 +4,12 @@ import ( "bytes" "context" "encoding/json" - "fmt" + "errors" "net/http" "path" "github.com/influxdata/platform" - "github.com/influxdata/platform/kit/errors" + kerrors "github.com/influxdata/platform/kit/errors" "github.com/julienschmidt/httprouter" ) @@ -40,17 +40,17 @@ func (h *BucketHandler) handlePostBucket(w http.ResponseWriter, r *http.Request) req, err := decodePostBucketRequest(ctx, r) if err != nil { - errors.EncodeHTTP(ctx, err, w) + kerrors.EncodeHTTP(ctx, err, w) return } if err := h.BucketService.CreateBucket(ctx, req.Bucket); err != nil { - errors.EncodeHTTP(ctx, err, w) + kerrors.EncodeHTTP(ctx, err, w) return } if err := encodeResponse(ctx, w, http.StatusCreated, req.Bucket); err != nil { - errors.EncodeHTTP(ctx, err, w) + kerrors.EncodeHTTP(ctx, err, w) return } } @@ -76,18 +76,18 @@ func (h *BucketHandler) handleGetBucket(w http.ResponseWriter, r *http.Request) req, err := decodeGetBucketRequest(ctx, r) if err != nil { - errors.EncodeHTTP(ctx, err, w) + kerrors.EncodeHTTP(ctx, err, w) return } b, err := h.BucketService.FindBucketByID(ctx, req.BucketID) if err != nil { - errors.EncodeHTTP(ctx, err, w) + kerrors.EncodeHTTP(ctx, err, w) return } if err := encodeResponse(ctx, w, http.StatusOK, b); err != nil { - errors.EncodeHTTP(ctx, err, w) + kerrors.EncodeHTTP(ctx, err, w) return } } @@ -100,7 +100,7 @@ func decodeGetBucketRequest(ctx context.Context, r *http.Request) (*getBucketReq params := httprouter.ParamsFromContext(ctx) id := params.ByName("id") if id == "" { - return nil, errors.InvalidDataf("url missing id") + return nil, kerrors.InvalidDataf("url missing id") } var i platform.ID @@ -120,12 +120,12 @@ func (h *BucketHandler) handleDeleteBucket(w http.ResponseWriter, r *http.Reques req, err := decodeDeleteBucketRequest(ctx, r) if err != nil { - errors.EncodeHTTP(ctx, err, w) + kerrors.EncodeHTTP(ctx, err, w) return } if err := h.BucketService.DeleteBucket(ctx, req.BucketID); err != nil { - errors.EncodeHTTP(ctx, err, w) + kerrors.EncodeHTTP(ctx, err, w) return } @@ -140,7 +140,7 @@ func decodeDeleteBucketRequest(ctx context.Context, r *http.Request) (*deleteBuc params := httprouter.ParamsFromContext(ctx) id := params.ByName("id") if id == "" { - return nil, errors.InvalidDataf("url missing id") + return nil, kerrors.InvalidDataf("url missing id") } var i platform.ID @@ -160,18 +160,18 @@ func (h *BucketHandler) handleGetBuckets(w http.ResponseWriter, r *http.Request) req, err := decodeGetBucketsRequest(ctx, r) if err != nil { - errors.EncodeHTTP(ctx, err, w) + kerrors.EncodeHTTP(ctx, err, w) return } bs, _, err := h.BucketService.FindBuckets(ctx, req.filter) if err != nil { - errors.EncodeHTTP(ctx, err, w) + kerrors.EncodeHTTP(ctx, err, w) return } if err := encodeResponse(ctx, w, http.StatusOK, bs); err != nil { - errors.EncodeHTTP(ctx, err, w) + kerrors.EncodeHTTP(ctx, err, w) return } } @@ -215,18 +215,18 @@ func (h *BucketHandler) handlePatchBucket(w http.ResponseWriter, r *http.Request req, err := decodePatchBucketRequest(ctx, r) if err != nil { - errors.EncodeHTTP(ctx, err, w) + kerrors.EncodeHTTP(ctx, err, w) return } b, err := h.BucketService.UpdateBucket(ctx, req.BucketID, req.Update) if err != nil { - errors.EncodeHTTP(ctx, err, w) + kerrors.EncodeHTTP(ctx, err, w) return } if err := encodeResponse(ctx, w, http.StatusOK, b); err != nil { - errors.EncodeHTTP(ctx, err, w) + kerrors.EncodeHTTP(ctx, err, w) return } } @@ -240,7 +240,7 @@ func decodePatchBucketRequest(ctx context.Context, r *http.Request) (*patchBucke params := httprouter.ParamsFromContext(ctx) id := params.ByName("id") if id == "" { - return nil, errors.InvalidDataf("url missing id") + return nil, kerrors.InvalidDataf("url missing id") } var i platform.ID @@ -290,7 +290,7 @@ func (s *BucketService) FindBucketByID(ctx context.Context, id platform.ID) (*pl } if resp.StatusCode != http.StatusOK { - return nil, fmt.Errorf(resp.Header.Get("X-Influx-Error")) + return nil, errors.New(resp.Header.Get("X-Influx-Error")) } var b platform.Bucket @@ -310,7 +310,7 @@ func (s *BucketService) FindBucket(ctx context.Context, filter platform.BucketFi } if n == 0 { - return nil, fmt.Errorf("found no matching buckets") + return nil, errors.New("found no matching buckets") } return bs[0], nil @@ -353,7 +353,7 @@ func (s *BucketService) FindBuckets(ctx context.Context, filter platform.BucketF } if resp.StatusCode != http.StatusOK { - return nil, 0, fmt.Errorf(resp.Header.Get("X-Influx-Error")) + return nil, 0, errors.New(resp.Header.Get("X-Influx-Error")) } var bs []*platform.Bucket @@ -393,7 +393,7 @@ func (s *BucketService) CreateBucket(ctx context.Context, b *platform.Bucket) er } if resp.StatusCode != http.StatusCreated { - return fmt.Errorf(resp.Header.Get("X-Influx-Error")) + return errors.New(resp.Header.Get("X-Influx-Error")) } if err := json.NewDecoder(resp.Body).Decode(b); err != nil { @@ -432,7 +432,7 @@ func (s *BucketService) UpdateBucket(ctx context.Context, id platform.ID, upd pl } if resp.StatusCode != http.StatusOK { - return nil, fmt.Errorf(resp.Header.Get("X-Influx-Error")) + return nil, errors.New(resp.Header.Get("X-Influx-Error")) } var b platform.Bucket @@ -468,7 +468,7 @@ func (s *BucketService) DeleteBucket(ctx context.Context, id platform.ID) error return nil } - return fmt.Errorf(resp.Header.Get("X-Influx-Error")) + return errors.New(resp.Header.Get("X-Influx-Error")) } func bucketIDPath(id platform.ID) string { diff --git a/http/org_service.go b/http/org_service.go index 06f14d16d8..a3d91b5073 100644 --- a/http/org_service.go +++ b/http/org_service.go @@ -4,12 +4,12 @@ import ( "bytes" "context" "encoding/json" - "fmt" + "errors" "net/http" "path" "github.com/influxdata/platform" - "github.com/influxdata/platform/kit/errors" + kerrors "github.com/influxdata/platform/kit/errors" "github.com/julienschmidt/httprouter" ) @@ -40,17 +40,17 @@ func (h *OrgHandler) handlePostOrg(w http.ResponseWriter, r *http.Request) { req, err := decodePostOrgRequest(ctx, r) if err != nil { - errors.EncodeHTTP(ctx, err, w) + kerrors.EncodeHTTP(ctx, err, w) return } if err := h.OrganizationService.CreateOrganization(ctx, req.Org); err != nil { - errors.EncodeHTTP(ctx, err, w) + kerrors.EncodeHTTP(ctx, err, w) return } if err := encodeResponse(ctx, w, http.StatusCreated, req.Org); err != nil { - errors.EncodeHTTP(ctx, err, w) + kerrors.EncodeHTTP(ctx, err, w) return } } @@ -76,18 +76,18 @@ func (h *OrgHandler) handleGetOrg(w http.ResponseWriter, r *http.Request) { req, err := decodeGetOrgRequest(ctx, r) if err != nil { - errors.EncodeHTTP(ctx, err, w) + kerrors.EncodeHTTP(ctx, err, w) return } b, err := h.OrganizationService.FindOrganizationByID(ctx, req.OrgID) if err != nil { - errors.EncodeHTTP(ctx, err, w) + kerrors.EncodeHTTP(ctx, err, w) return } if err := encodeResponse(ctx, w, http.StatusOK, b); err != nil { - errors.EncodeHTTP(ctx, err, w) + kerrors.EncodeHTTP(ctx, err, w) return } } @@ -100,7 +100,7 @@ func decodeGetOrgRequest(ctx context.Context, r *http.Request) (*getOrgRequest, params := httprouter.ParamsFromContext(ctx) id := params.ByName("id") if id == "" { - return nil, errors.InvalidDataf("url missing id") + return nil, kerrors.InvalidDataf("url missing id") } var i platform.ID @@ -121,18 +121,18 @@ func (h *OrgHandler) handleGetOrgs(w http.ResponseWriter, r *http.Request) { req, err := decodeGetOrgsRequest(ctx, r) if err != nil { - errors.EncodeHTTP(ctx, err, w) + kerrors.EncodeHTTP(ctx, err, w) return } orgs, _, err := h.OrganizationService.FindOrganizations(ctx, req.filter) if err != nil { - errors.EncodeHTTP(ctx, err, w) + kerrors.EncodeHTTP(ctx, err, w) return } if err := encodeResponse(ctx, w, http.StatusOK, orgs); err != nil { - errors.EncodeHTTP(ctx, err, w) + kerrors.EncodeHTTP(ctx, err, w) return } } @@ -165,12 +165,12 @@ func (h *OrgHandler) handleDeleteOrg(w http.ResponseWriter, r *http.Request) { req, err := decodeDeleteOrganizationRequest(ctx, r) if err != nil { - errors.EncodeHTTP(ctx, err, w) + kerrors.EncodeHTTP(ctx, err, w) return } if err := h.OrganizationService.DeleteOrganization(ctx, req.OrganizationID); err != nil { - errors.EncodeHTTP(ctx, err, w) + kerrors.EncodeHTTP(ctx, err, w) return } @@ -185,7 +185,7 @@ func decodeDeleteOrganizationRequest(ctx context.Context, r *http.Request) (*del params := httprouter.ParamsFromContext(ctx) id := params.ByName("id") if id == "" { - return nil, errors.InvalidDataf("url missing id") + return nil, kerrors.InvalidDataf("url missing id") } var i platform.ID @@ -205,18 +205,18 @@ func (h *OrgHandler) handlePatchOrg(w http.ResponseWriter, r *http.Request) { req, err := decodePatchOrgRequest(ctx, r) if err != nil { - errors.EncodeHTTP(ctx, err, w) + kerrors.EncodeHTTP(ctx, err, w) return } o, err := h.OrganizationService.UpdateOrganization(ctx, req.OrgID, req.Update) if err != nil { - errors.EncodeHTTP(ctx, err, w) + kerrors.EncodeHTTP(ctx, err, w) return } if err := encodeResponse(ctx, w, http.StatusOK, o); err != nil { - errors.EncodeHTTP(ctx, err, w) + kerrors.EncodeHTTP(ctx, err, w) return } } @@ -230,7 +230,7 @@ func decodePatchOrgRequest(ctx context.Context, r *http.Request) (*patchOrgReque params := httprouter.ParamsFromContext(ctx) id := params.ByName("id") if id == "" { - return nil, errors.InvalidDataf("url missing id") + return nil, kerrors.InvalidDataf("url missing id") } var i platform.ID @@ -272,7 +272,7 @@ func (s *OrganizationService) FindOrganization(ctx context.Context, filter platf } if n < 1 { - return nil, fmt.Errorf("expected at least one organization") + return nil, errors.New("expected at least one organization") } return os[0], nil @@ -307,7 +307,7 @@ func (s *OrganizationService) FindOrganizations(ctx context.Context, filter plat } if resp.StatusCode != http.StatusOK { - return nil, 0, fmt.Errorf(resp.Header.Get("X-Influx-Error")) + return nil, 0, errors.New(resp.Header.Get("X-Influx-Error")) } var os []*platform.Organization @@ -348,7 +348,7 @@ func (s *OrganizationService) CreateOrganization(ctx context.Context, o *platfor // TODO: this should really check the error from the headers if resp.StatusCode != http.StatusCreated { - return fmt.Errorf(resp.Header.Get("X-Influx-Error")) + return errors.New(resp.Header.Get("X-Influx-Error")) } if err := json.NewDecoder(resp.Body).Decode(o); err != nil { @@ -385,7 +385,7 @@ func (s *OrganizationService) UpdateOrganization(ctx context.Context, id platfor } if resp.StatusCode != http.StatusOK { - return nil, fmt.Errorf(resp.Header.Get("X-Influx-Error")) + return nil, errors.New(resp.Header.Get("X-Influx-Error")) } var o platform.Organization @@ -420,7 +420,7 @@ func (s *OrganizationService) DeleteOrganization(ctx context.Context, id platfor return nil } - return fmt.Errorf(resp.Header.Get("X-Influx-Error")) + return errors.New(resp.Header.Get("X-Influx-Error")) } func organizationIDPath(id platform.ID) string { diff --git a/http/usage_service.go b/http/usage_service.go index 944b8808e9..b0c4c043bb 100644 --- a/http/usage_service.go +++ b/http/usage_service.go @@ -2,12 +2,12 @@ package http import ( "context" - "fmt" + "errors" "net/http" "time" "github.com/influxdata/platform" - "github.com/influxdata/platform/kit/errors" + kerrors "github.com/influxdata/platform/kit/errors" "github.com/julienschmidt/httprouter" ) @@ -34,18 +34,18 @@ func (h *UsageHandler) handleGetUsage(w http.ResponseWriter, r *http.Request) { req, err := decodeGetUsageRequest(ctx, r) if err != nil { - errors.EncodeHTTP(ctx, err, w) + kerrors.EncodeHTTP(ctx, err, w) return } b, err := h.UsageService.GetUsage(ctx, req.filter) if err != nil { - errors.EncodeHTTP(ctx, err, w) + kerrors.EncodeHTTP(ctx, err, w) return } if err := encodeResponse(ctx, w, http.StatusOK, b); err != nil { - errors.EncodeHTTP(ctx, err, w) + kerrors.EncodeHTTP(ctx, err, w) return } } @@ -80,10 +80,10 @@ func decodeGetUsageRequest(ctx context.Context, r *http.Request) (*getUsageReque stop := qp.Get("stop") if start == "" && stop != "" { - return nil, fmt.Errorf("start query param required") + return nil, errors.New("start query param required") } if start == "" && stop != "" { - return nil, fmt.Errorf("stop query param required") + return nil, errors.New("stop query param required") } if start == "" && stop == "" { diff --git a/http/user_service.go b/http/user_service.go index ae54db837d..4eab5d02e4 100644 --- a/http/user_service.go +++ b/http/user_service.go @@ -4,19 +4,18 @@ import ( "bytes" "context" "encoding/json" - "fmt" + "errors" "net/http" "path" "github.com/influxdata/platform" - "github.com/influxdata/platform/kit/errors" + kerrors "github.com/influxdata/platform/kit/errors" "github.com/julienschmidt/httprouter" ) // UserHandler represents an HTTP API handler for users. type UserHandler struct { *httprouter.Router - UserService platform.UserService } @@ -40,17 +39,17 @@ func (h *UserHandler) handlePostUser(w http.ResponseWriter, r *http.Request) { req, err := decodePostUserRequest(ctx, r) if err != nil { - errors.EncodeHTTP(ctx, err, w) + kerrors.EncodeHTTP(ctx, err, w) return } if err := h.UserService.CreateUser(ctx, req.User); err != nil { - errors.EncodeHTTP(ctx, err, w) + kerrors.EncodeHTTP(ctx, err, w) return } if err := encodeResponse(ctx, w, http.StatusCreated, req.User); err != nil { - errors.EncodeHTTP(ctx, err, w) + kerrors.EncodeHTTP(ctx, err, w) return } } @@ -76,18 +75,18 @@ func (h *UserHandler) handleGetUser(w http.ResponseWriter, r *http.Request) { req, err := decodeGetUserRequest(ctx, r) if err != nil { - errors.EncodeHTTP(ctx, err, w) + kerrors.EncodeHTTP(ctx, err, w) return } b, err := h.UserService.FindUserByID(ctx, req.UserID) if err != nil { - errors.EncodeHTTP(ctx, err, w) + kerrors.EncodeHTTP(ctx, err, w) return } if err := encodeResponse(ctx, w, http.StatusOK, b); err != nil { - errors.EncodeHTTP(ctx, err, w) + kerrors.EncodeHTTP(ctx, err, w) return } } @@ -100,7 +99,7 @@ func decodeGetUserRequest(ctx context.Context, r *http.Request) (*getUserRequest params := httprouter.ParamsFromContext(ctx) id := params.ByName("id") if id == "" { - return nil, errors.InvalidDataf("url missing id") + return nil, kerrors.InvalidDataf("url missing id") } var i platform.ID @@ -121,12 +120,12 @@ func (h *UserHandler) handleDeleteUser(w http.ResponseWriter, r *http.Request) { req, err := decodeDeleteUserRequest(ctx, r) if err != nil { - errors.EncodeHTTP(ctx, err, w) + kerrors.EncodeHTTP(ctx, err, w) return } if err := h.UserService.DeleteUser(ctx, req.UserID); err != nil { - errors.EncodeHTTP(ctx, err, w) + kerrors.EncodeHTTP(ctx, err, w) return } @@ -141,7 +140,7 @@ func decodeDeleteUserRequest(ctx context.Context, r *http.Request) (*deleteUserR params := httprouter.ParamsFromContext(ctx) id := params.ByName("id") if id == "" { - return nil, errors.InvalidDataf("url missing id") + return nil, kerrors.InvalidDataf("url missing id") } var i platform.ID @@ -160,18 +159,18 @@ func (h *UserHandler) handleGetUsers(w http.ResponseWriter, r *http.Request) { req, err := decodeGetUsersRequest(ctx, r) if err != nil { - errors.EncodeHTTP(ctx, err, w) + kerrors.EncodeHTTP(ctx, err, w) return } users, _, err := h.UserService.FindUsers(ctx, req.filter) if err != nil { - errors.EncodeHTTP(ctx, err, w) + kerrors.EncodeHTTP(ctx, err, w) return } if err := encodeResponse(ctx, w, http.StatusOK, users); err != nil { - errors.EncodeHTTP(ctx, err, w) + kerrors.EncodeHTTP(ctx, err, w) return } } @@ -204,18 +203,18 @@ func (h *UserHandler) handlePatchUser(w http.ResponseWriter, r *http.Request) { req, err := decodePatchUserRequest(ctx, r) if err != nil { - errors.EncodeHTTP(ctx, err, w) + kerrors.EncodeHTTP(ctx, err, w) return } b, err := h.UserService.UpdateUser(ctx, req.UserID, req.Update) if err != nil { - errors.EncodeHTTP(ctx, err, w) + kerrors.EncodeHTTP(ctx, err, w) return } if err := encodeResponse(ctx, w, http.StatusOK, b); err != nil { - errors.EncodeHTTP(ctx, err, w) + kerrors.EncodeHTTP(ctx, err, w) return } } @@ -229,7 +228,7 @@ func decodePatchUserRequest(ctx context.Context, r *http.Request) (*patchUserReq params := httprouter.ParamsFromContext(ctx) id := params.ByName("id") if id == "" { - return nil, errors.InvalidDataf("url missing id") + return nil, kerrors.InvalidDataf("url missing id") } var i platform.ID @@ -275,7 +274,7 @@ func (s *UserService) FindUserByID(ctx context.Context, id platform.ID) (*platfo } if resp.StatusCode != http.StatusOK { - return nil, fmt.Errorf(resp.Header.Get("X-Influx-Error")) + return nil, errors.New(resp.Header.Get("X-Influx-Error")) } var b platform.User @@ -295,7 +294,7 @@ func (s *UserService) FindUser(ctx context.Context, filter platform.UserFilter) } if n == 0 { - return nil, fmt.Errorf("found no matching user") + return nil, errors.New("found no matching user") } return users[0], nil @@ -332,7 +331,7 @@ func (s *UserService) FindUsers(ctx context.Context, filter platform.UserFilter, } if resp.StatusCode != http.StatusOK { - return nil, 0, fmt.Errorf(resp.Header.Get("X-Influx-Error")) + return nil, 0, errors.New(resp.Header.Get("X-Influx-Error")) } var bs []*platform.User @@ -375,7 +374,7 @@ func (s *UserService) CreateUser(ctx context.Context, u *platform.User) error { } if resp.StatusCode != http.StatusCreated { - return fmt.Errorf(resp.Header.Get("X-Influx-Error")) + return errors.New(resp.Header.Get("X-Influx-Error")) } if err := json.NewDecoder(resp.Body).Decode(u); err != nil { @@ -414,7 +413,7 @@ func (s *UserService) UpdateUser(ctx context.Context, id platform.ID, upd platfo } if resp.StatusCode != http.StatusOK { - return nil, fmt.Errorf(resp.Header.Get("X-Influx-Error")) + return nil, errors.New(resp.Header.Get("X-Influx-Error")) } var u platform.User @@ -446,7 +445,7 @@ func (s *UserService) DeleteUser(ctx context.Context, id platform.ID) error { } if resp.StatusCode != http.StatusAccepted { - return fmt.Errorf(resp.Header.Get("X-Influx-Error")) + return errors.New(resp.Header.Get("X-Influx-Error")) } return nil