Merge pull request #25 from influxdata/vet

fix and enable vet
pull/10616/head
Jorge Landivar 2018-05-23 00:22:42 -05:00 committed by GitHub
commit 435e38da9d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 106 additions and 105 deletions

View File

@ -9,10 +9,8 @@ jobs:
steps: steps:
- checkout - checkout
- run: make test - run: make test
- run: make vet
# TODO add these checks to the Makefile # TODO add these checks to the Makefile
# - run: go get -v -t -d ./... # - run: go get -v -t -d ./...
# - run: go get honnef.co/go/tools/cmd/megacheck # - run: go get honnef.co/go/tools/cmd/megacheck
# - run: go vet -v ./...
# - run: go test -v ./...
# - run: megacheck ./... # - run: megacheck ./...

View File

@ -16,6 +16,7 @@ GO_ARGS=-tags '$(GO_TAGS)'
export GO_BUILD=go build $(GO_ARGS) export GO_BUILD=go build $(GO_ARGS)
export GO_TEST=go test $(GO_ARGS) export GO_TEST=go test $(GO_ARGS)
export GO_GENERATE=go generate $(GO_ARGS) export GO_GENERATE=go generate $(GO_ARGS)
export GO_VET= go vet $(GO_ARGS)
# All go source files # All go source files
@ -87,6 +88,9 @@ test: all
test-race: all test-race: all
$(GO_TEST) -race ./... $(GO_TEST) -race ./...
vet: all
$(GO_VET) -v ./...
bench: all bench: all
$(GO_TEST) -bench=. -run=^$$ ./... $(GO_TEST) -bench=. -run=^$$ ./...

View File

@ -4,14 +4,14 @@ import (
"bytes" "bytes"
"context" "context"
"encoding/json" "encoding/json"
"fmt" "errors"
"net/http" "net/http"
"path" "path"
"go.uber.org/zap" "go.uber.org/zap"
"github.com/influxdata/platform" "github.com/influxdata/platform"
"github.com/influxdata/platform/kit/errors" kerrors "github.com/influxdata/platform/kit/errors"
"github.com/julienschmidt/httprouter" "github.com/julienschmidt/httprouter"
) )
@ -43,7 +43,7 @@ func (h *AuthorizationHandler) handlePostAuthorization(w http.ResponseWriter, r
req, err := decodePostAuthorizationRequest(ctx, r) req, err := decodePostAuthorizationRequest(ctx, r)
if err != nil { if err != nil {
h.Logger.Info("failed to decode request", zap.String("handler", "postAuthorization"), zap.Error(err)) 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 return
} }
@ -51,13 +51,13 @@ func (h *AuthorizationHandler) handlePostAuthorization(w http.ResponseWriter, r
if err := h.AuthorizationService.CreateAuthorization(ctx, req.Authorization); err != nil { if err := h.AuthorizationService.CreateAuthorization(ctx, req.Authorization); err != nil {
// Don't log here, it should already be handled by the service // Don't log here, it should already be handled by the service
errors.EncodeHTTP(ctx, err, w) kerrors.EncodeHTTP(ctx, err, w)
return return
} }
if err := encodeResponse(ctx, w, http.StatusCreated, req.Authorization); err != nil { 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)) 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 return
} }
} }
@ -84,20 +84,20 @@ func (h *AuthorizationHandler) handleGetAuthorizations(w http.ResponseWriter, r
req, err := decodeGetAuthorizationsRequest(ctx, r) req, err := decodeGetAuthorizationsRequest(ctx, r)
if err != nil { if err != nil {
h.Logger.Info("failed to decode request", zap.String("handler", "getAuthorizations"), zap.Error(err)) 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 return
} }
as, _, err := h.AuthorizationService.FindAuthorizations(ctx, req.filter) as, _, err := h.AuthorizationService.FindAuthorizations(ctx, req.filter)
if err != nil { if err != nil {
// Don't log here, it should already be handled by the service // Don't log here, it should already be handled by the service
errors.EncodeHTTP(ctx, err, w) kerrors.EncodeHTTP(ctx, err, w)
return return
} }
if err := encodeResponse(ctx, w, http.StatusOK, as); err != nil { if err := encodeResponse(ctx, w, http.StatusOK, as); err != nil {
h.Logger.Info("failed to encode response", zap.String("handler", "getAuthorizations"), zap.Error(err)) 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 return
} }
} }
@ -142,20 +142,20 @@ func (h *AuthorizationHandler) handleGetAuthorization(w http.ResponseWriter, r *
req, err := decodeGetAuthorizationRequest(ctx, r) req, err := decodeGetAuthorizationRequest(ctx, r)
if err != nil { if err != nil {
h.Logger.Info("failed to decode request", zap.String("handler", "getAuthorization"), zap.Error(err)) 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 return
} }
a, err := h.AuthorizationService.FindAuthorizationByID(ctx, req.ID) a, err := h.AuthorizationService.FindAuthorizationByID(ctx, req.ID)
if err != nil { if err != nil {
// Don't log here, it should already be handled by the service // Don't log here, it should already be handled by the service
errors.EncodeHTTP(ctx, err, w) kerrors.EncodeHTTP(ctx, err, w)
return return
} }
if err := encodeResponse(ctx, w, http.StatusOK, a); err != nil { if err := encodeResponse(ctx, w, http.StatusOK, a); err != nil {
h.Logger.Info("failed to encode response", zap.String("handler", "getAuthorization"), zap.Error(err)) 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 return
} }
} }
@ -168,7 +168,7 @@ func decodeGetAuthorizationRequest(ctx context.Context, r *http.Request) (*getAu
params := httprouter.ParamsFromContext(ctx) params := httprouter.ParamsFromContext(ctx)
id := params.ByName("id") id := params.ByName("id")
if id == "" { if id == "" {
return nil, errors.InvalidDataf("url missing id") return nil, kerrors.InvalidDataf("url missing id")
} }
var i platform.ID var i platform.ID
@ -188,13 +188,13 @@ func (h *AuthorizationHandler) handleDeleteAuthorization(w http.ResponseWriter,
req, err := decodeDeleteAuthorizationRequest(ctx, r) req, err := decodeDeleteAuthorizationRequest(ctx, r)
if err != nil { if err != nil {
h.Logger.Info("failed to decode request", zap.String("handler", "deleteAuthorization"), zap.Error(err)) 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 return
} }
if err := h.AuthorizationService.DeleteAuthorization(ctx, req.ID); err != nil { if err := h.AuthorizationService.DeleteAuthorization(ctx, req.ID); err != nil {
// Don't log here, it should already be handled by the service // Don't log here, it should already be handled by the service
errors.EncodeHTTP(ctx, err, w) kerrors.EncodeHTTP(ctx, err, w)
return return
} }
@ -209,7 +209,7 @@ func decodeDeleteAuthorizationRequest(ctx context.Context, r *http.Request) (*de
params := httprouter.ParamsFromContext(ctx) params := httprouter.ParamsFromContext(ctx)
id := params.ByName("id") id := params.ByName("id")
if id == "" { if id == "" {
return nil, errors.InvalidDataf("url missing id") return nil, kerrors.InvalidDataf("url missing id")
} }
var i platform.ID var i platform.ID
@ -250,7 +250,7 @@ func (s *AuthorizationService) FindAuthorizationByID(ctx context.Context, id pla
} }
if resp.StatusCode != http.StatusOK { 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 var b platform.Authorization
@ -264,7 +264,7 @@ func (s *AuthorizationService) FindAuthorizationByID(ctx context.Context, id pla
// FindAuthorizationByToken returns a single authorization by Token. // FindAuthorizationByToken returns a single authorization by Token.
func (s *AuthorizationService) FindAuthorizationByToken(ctx context.Context, token string) (*platform.Authorization, error) { 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. // 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 { 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 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 // TODO: this should really check the error from the headers
if resp.StatusCode != http.StatusCreated { 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 { 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 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 { func authorizationIDPath(id platform.ID) string {

View File

@ -4,12 +4,12 @@ import (
"bytes" "bytes"
"context" "context"
"encoding/json" "encoding/json"
"fmt" "errors"
"net/http" "net/http"
"path" "path"
"github.com/influxdata/platform" "github.com/influxdata/platform"
"github.com/influxdata/platform/kit/errors" kerrors "github.com/influxdata/platform/kit/errors"
"github.com/julienschmidt/httprouter" "github.com/julienschmidt/httprouter"
) )
@ -40,17 +40,17 @@ func (h *BucketHandler) handlePostBucket(w http.ResponseWriter, r *http.Request)
req, err := decodePostBucketRequest(ctx, r) req, err := decodePostBucketRequest(ctx, r)
if err != nil { if err != nil {
errors.EncodeHTTP(ctx, err, w) kerrors.EncodeHTTP(ctx, err, w)
return return
} }
if err := h.BucketService.CreateBucket(ctx, req.Bucket); err != nil { if err := h.BucketService.CreateBucket(ctx, req.Bucket); err != nil {
errors.EncodeHTTP(ctx, err, w) kerrors.EncodeHTTP(ctx, err, w)
return return
} }
if err := encodeResponse(ctx, w, http.StatusCreated, req.Bucket); err != nil { if err := encodeResponse(ctx, w, http.StatusCreated, req.Bucket); err != nil {
errors.EncodeHTTP(ctx, err, w) kerrors.EncodeHTTP(ctx, err, w)
return return
} }
} }
@ -76,18 +76,18 @@ func (h *BucketHandler) handleGetBucket(w http.ResponseWriter, r *http.Request)
req, err := decodeGetBucketRequest(ctx, r) req, err := decodeGetBucketRequest(ctx, r)
if err != nil { if err != nil {
errors.EncodeHTTP(ctx, err, w) kerrors.EncodeHTTP(ctx, err, w)
return return
} }
b, err := h.BucketService.FindBucketByID(ctx, req.BucketID) b, err := h.BucketService.FindBucketByID(ctx, req.BucketID)
if err != nil { if err != nil {
errors.EncodeHTTP(ctx, err, w) kerrors.EncodeHTTP(ctx, err, w)
return return
} }
if err := encodeResponse(ctx, w, http.StatusOK, b); err != nil { if err := encodeResponse(ctx, w, http.StatusOK, b); err != nil {
errors.EncodeHTTP(ctx, err, w) kerrors.EncodeHTTP(ctx, err, w)
return return
} }
} }
@ -100,7 +100,7 @@ func decodeGetBucketRequest(ctx context.Context, r *http.Request) (*getBucketReq
params := httprouter.ParamsFromContext(ctx) params := httprouter.ParamsFromContext(ctx)
id := params.ByName("id") id := params.ByName("id")
if id == "" { if id == "" {
return nil, errors.InvalidDataf("url missing id") return nil, kerrors.InvalidDataf("url missing id")
} }
var i platform.ID var i platform.ID
@ -120,12 +120,12 @@ func (h *BucketHandler) handleDeleteBucket(w http.ResponseWriter, r *http.Reques
req, err := decodeDeleteBucketRequest(ctx, r) req, err := decodeDeleteBucketRequest(ctx, r)
if err != nil { if err != nil {
errors.EncodeHTTP(ctx, err, w) kerrors.EncodeHTTP(ctx, err, w)
return return
} }
if err := h.BucketService.DeleteBucket(ctx, req.BucketID); err != nil { if err := h.BucketService.DeleteBucket(ctx, req.BucketID); err != nil {
errors.EncodeHTTP(ctx, err, w) kerrors.EncodeHTTP(ctx, err, w)
return return
} }
@ -140,7 +140,7 @@ func decodeDeleteBucketRequest(ctx context.Context, r *http.Request) (*deleteBuc
params := httprouter.ParamsFromContext(ctx) params := httprouter.ParamsFromContext(ctx)
id := params.ByName("id") id := params.ByName("id")
if id == "" { if id == "" {
return nil, errors.InvalidDataf("url missing id") return nil, kerrors.InvalidDataf("url missing id")
} }
var i platform.ID var i platform.ID
@ -160,18 +160,18 @@ func (h *BucketHandler) handleGetBuckets(w http.ResponseWriter, r *http.Request)
req, err := decodeGetBucketsRequest(ctx, r) req, err := decodeGetBucketsRequest(ctx, r)
if err != nil { if err != nil {
errors.EncodeHTTP(ctx, err, w) kerrors.EncodeHTTP(ctx, err, w)
return return
} }
bs, _, err := h.BucketService.FindBuckets(ctx, req.filter) bs, _, err := h.BucketService.FindBuckets(ctx, req.filter)
if err != nil { if err != nil {
errors.EncodeHTTP(ctx, err, w) kerrors.EncodeHTTP(ctx, err, w)
return return
} }
if err := encodeResponse(ctx, w, http.StatusOK, bs); err != nil { if err := encodeResponse(ctx, w, http.StatusOK, bs); err != nil {
errors.EncodeHTTP(ctx, err, w) kerrors.EncodeHTTP(ctx, err, w)
return return
} }
} }
@ -215,18 +215,18 @@ func (h *BucketHandler) handlePatchBucket(w http.ResponseWriter, r *http.Request
req, err := decodePatchBucketRequest(ctx, r) req, err := decodePatchBucketRequest(ctx, r)
if err != nil { if err != nil {
errors.EncodeHTTP(ctx, err, w) kerrors.EncodeHTTP(ctx, err, w)
return return
} }
b, err := h.BucketService.UpdateBucket(ctx, req.BucketID, req.Update) b, err := h.BucketService.UpdateBucket(ctx, req.BucketID, req.Update)
if err != nil { if err != nil {
errors.EncodeHTTP(ctx, err, w) kerrors.EncodeHTTP(ctx, err, w)
return return
} }
if err := encodeResponse(ctx, w, http.StatusOK, b); err != nil { if err := encodeResponse(ctx, w, http.StatusOK, b); err != nil {
errors.EncodeHTTP(ctx, err, w) kerrors.EncodeHTTP(ctx, err, w)
return return
} }
} }
@ -240,7 +240,7 @@ func decodePatchBucketRequest(ctx context.Context, r *http.Request) (*patchBucke
params := httprouter.ParamsFromContext(ctx) params := httprouter.ParamsFromContext(ctx)
id := params.ByName("id") id := params.ByName("id")
if id == "" { if id == "" {
return nil, errors.InvalidDataf("url missing id") return nil, kerrors.InvalidDataf("url missing id")
} }
var i platform.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 { 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 var b platform.Bucket
@ -310,7 +310,7 @@ func (s *BucketService) FindBucket(ctx context.Context, filter platform.BucketFi
} }
if n == 0 { if n == 0 {
return nil, fmt.Errorf("found no matching buckets") return nil, errors.New("found no matching buckets")
} }
return bs[0], nil return bs[0], nil
@ -353,7 +353,7 @@ func (s *BucketService) FindBuckets(ctx context.Context, filter platform.BucketF
} }
if resp.StatusCode != http.StatusOK { 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 var bs []*platform.Bucket
@ -393,7 +393,7 @@ func (s *BucketService) CreateBucket(ctx context.Context, b *platform.Bucket) er
} }
if resp.StatusCode != http.StatusCreated { 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 { 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 { 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 var b platform.Bucket
@ -468,7 +468,7 @@ func (s *BucketService) DeleteBucket(ctx context.Context, id platform.ID) error
return nil 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 { func bucketIDPath(id platform.ID) string {

View File

@ -4,12 +4,12 @@ import (
"bytes" "bytes"
"context" "context"
"encoding/json" "encoding/json"
"fmt" "errors"
"net/http" "net/http"
"path" "path"
"github.com/influxdata/platform" "github.com/influxdata/platform"
"github.com/influxdata/platform/kit/errors" kerrors "github.com/influxdata/platform/kit/errors"
"github.com/julienschmidt/httprouter" "github.com/julienschmidt/httprouter"
) )
@ -40,17 +40,17 @@ func (h *OrgHandler) handlePostOrg(w http.ResponseWriter, r *http.Request) {
req, err := decodePostOrgRequest(ctx, r) req, err := decodePostOrgRequest(ctx, r)
if err != nil { if err != nil {
errors.EncodeHTTP(ctx, err, w) kerrors.EncodeHTTP(ctx, err, w)
return return
} }
if err := h.OrganizationService.CreateOrganization(ctx, req.Org); err != nil { if err := h.OrganizationService.CreateOrganization(ctx, req.Org); err != nil {
errors.EncodeHTTP(ctx, err, w) kerrors.EncodeHTTP(ctx, err, w)
return return
} }
if err := encodeResponse(ctx, w, http.StatusCreated, req.Org); err != nil { if err := encodeResponse(ctx, w, http.StatusCreated, req.Org); err != nil {
errors.EncodeHTTP(ctx, err, w) kerrors.EncodeHTTP(ctx, err, w)
return return
} }
} }
@ -76,18 +76,18 @@ func (h *OrgHandler) handleGetOrg(w http.ResponseWriter, r *http.Request) {
req, err := decodeGetOrgRequest(ctx, r) req, err := decodeGetOrgRequest(ctx, r)
if err != nil { if err != nil {
errors.EncodeHTTP(ctx, err, w) kerrors.EncodeHTTP(ctx, err, w)
return return
} }
b, err := h.OrganizationService.FindOrganizationByID(ctx, req.OrgID) b, err := h.OrganizationService.FindOrganizationByID(ctx, req.OrgID)
if err != nil { if err != nil {
errors.EncodeHTTP(ctx, err, w) kerrors.EncodeHTTP(ctx, err, w)
return return
} }
if err := encodeResponse(ctx, w, http.StatusOK, b); err != nil { if err := encodeResponse(ctx, w, http.StatusOK, b); err != nil {
errors.EncodeHTTP(ctx, err, w) kerrors.EncodeHTTP(ctx, err, w)
return return
} }
} }
@ -100,7 +100,7 @@ func decodeGetOrgRequest(ctx context.Context, r *http.Request) (*getOrgRequest,
params := httprouter.ParamsFromContext(ctx) params := httprouter.ParamsFromContext(ctx)
id := params.ByName("id") id := params.ByName("id")
if id == "" { if id == "" {
return nil, errors.InvalidDataf("url missing id") return nil, kerrors.InvalidDataf("url missing id")
} }
var i platform.ID var i platform.ID
@ -121,18 +121,18 @@ func (h *OrgHandler) handleGetOrgs(w http.ResponseWriter, r *http.Request) {
req, err := decodeGetOrgsRequest(ctx, r) req, err := decodeGetOrgsRequest(ctx, r)
if err != nil { if err != nil {
errors.EncodeHTTP(ctx, err, w) kerrors.EncodeHTTP(ctx, err, w)
return return
} }
orgs, _, err := h.OrganizationService.FindOrganizations(ctx, req.filter) orgs, _, err := h.OrganizationService.FindOrganizations(ctx, req.filter)
if err != nil { if err != nil {
errors.EncodeHTTP(ctx, err, w) kerrors.EncodeHTTP(ctx, err, w)
return return
} }
if err := encodeResponse(ctx, w, http.StatusOK, orgs); err != nil { if err := encodeResponse(ctx, w, http.StatusOK, orgs); err != nil {
errors.EncodeHTTP(ctx, err, w) kerrors.EncodeHTTP(ctx, err, w)
return return
} }
} }
@ -165,12 +165,12 @@ func (h *OrgHandler) handleDeleteOrg(w http.ResponseWriter, r *http.Request) {
req, err := decodeDeleteOrganizationRequest(ctx, r) req, err := decodeDeleteOrganizationRequest(ctx, r)
if err != nil { if err != nil {
errors.EncodeHTTP(ctx, err, w) kerrors.EncodeHTTP(ctx, err, w)
return return
} }
if err := h.OrganizationService.DeleteOrganization(ctx, req.OrganizationID); err != nil { if err := h.OrganizationService.DeleteOrganization(ctx, req.OrganizationID); err != nil {
errors.EncodeHTTP(ctx, err, w) kerrors.EncodeHTTP(ctx, err, w)
return return
} }
@ -185,7 +185,7 @@ func decodeDeleteOrganizationRequest(ctx context.Context, r *http.Request) (*del
params := httprouter.ParamsFromContext(ctx) params := httprouter.ParamsFromContext(ctx)
id := params.ByName("id") id := params.ByName("id")
if id == "" { if id == "" {
return nil, errors.InvalidDataf("url missing id") return nil, kerrors.InvalidDataf("url missing id")
} }
var i platform.ID var i platform.ID
@ -205,18 +205,18 @@ func (h *OrgHandler) handlePatchOrg(w http.ResponseWriter, r *http.Request) {
req, err := decodePatchOrgRequest(ctx, r) req, err := decodePatchOrgRequest(ctx, r)
if err != nil { if err != nil {
errors.EncodeHTTP(ctx, err, w) kerrors.EncodeHTTP(ctx, err, w)
return return
} }
o, err := h.OrganizationService.UpdateOrganization(ctx, req.OrgID, req.Update) o, err := h.OrganizationService.UpdateOrganization(ctx, req.OrgID, req.Update)
if err != nil { if err != nil {
errors.EncodeHTTP(ctx, err, w) kerrors.EncodeHTTP(ctx, err, w)
return return
} }
if err := encodeResponse(ctx, w, http.StatusOK, o); err != nil { if err := encodeResponse(ctx, w, http.StatusOK, o); err != nil {
errors.EncodeHTTP(ctx, err, w) kerrors.EncodeHTTP(ctx, err, w)
return return
} }
} }
@ -230,7 +230,7 @@ func decodePatchOrgRequest(ctx context.Context, r *http.Request) (*patchOrgReque
params := httprouter.ParamsFromContext(ctx) params := httprouter.ParamsFromContext(ctx)
id := params.ByName("id") id := params.ByName("id")
if id == "" { if id == "" {
return nil, errors.InvalidDataf("url missing id") return nil, kerrors.InvalidDataf("url missing id")
} }
var i platform.ID var i platform.ID
@ -272,7 +272,7 @@ func (s *OrganizationService) FindOrganization(ctx context.Context, filter platf
} }
if n < 1 { 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 return os[0], nil
@ -307,7 +307,7 @@ func (s *OrganizationService) FindOrganizations(ctx context.Context, filter plat
} }
if resp.StatusCode != http.StatusOK { 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 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 // TODO: this should really check the error from the headers
if resp.StatusCode != http.StatusCreated { 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 { 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 { 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 var o platform.Organization
@ -420,7 +420,7 @@ func (s *OrganizationService) DeleteOrganization(ctx context.Context, id platfor
return nil 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 { func organizationIDPath(id platform.ID) string {

View File

@ -2,12 +2,12 @@ package http
import ( import (
"context" "context"
"fmt" "errors"
"net/http" "net/http"
"time" "time"
"github.com/influxdata/platform" "github.com/influxdata/platform"
"github.com/influxdata/platform/kit/errors" kerrors "github.com/influxdata/platform/kit/errors"
"github.com/julienschmidt/httprouter" "github.com/julienschmidt/httprouter"
) )
@ -34,18 +34,18 @@ func (h *UsageHandler) handleGetUsage(w http.ResponseWriter, r *http.Request) {
req, err := decodeGetUsageRequest(ctx, r) req, err := decodeGetUsageRequest(ctx, r)
if err != nil { if err != nil {
errors.EncodeHTTP(ctx, err, w) kerrors.EncodeHTTP(ctx, err, w)
return return
} }
b, err := h.UsageService.GetUsage(ctx, req.filter) b, err := h.UsageService.GetUsage(ctx, req.filter)
if err != nil { if err != nil {
errors.EncodeHTTP(ctx, err, w) kerrors.EncodeHTTP(ctx, err, w)
return return
} }
if err := encodeResponse(ctx, w, http.StatusOK, b); err != nil { if err := encodeResponse(ctx, w, http.StatusOK, b); err != nil {
errors.EncodeHTTP(ctx, err, w) kerrors.EncodeHTTP(ctx, err, w)
return return
} }
} }
@ -80,10 +80,10 @@ func decodeGetUsageRequest(ctx context.Context, r *http.Request) (*getUsageReque
stop := qp.Get("stop") stop := qp.Get("stop")
if start == "" && stop != "" { if start == "" && stop != "" {
return nil, fmt.Errorf("start query param required") return nil, errors.New("start query param required")
} }
if start == "" && stop != "" { if start == "" && stop != "" {
return nil, fmt.Errorf("stop query param required") return nil, errors.New("stop query param required")
} }
if start == "" && stop == "" { if start == "" && stop == "" {

View File

@ -4,19 +4,18 @@ import (
"bytes" "bytes"
"context" "context"
"encoding/json" "encoding/json"
"fmt" "errors"
"net/http" "net/http"
"path" "path"
"github.com/influxdata/platform" "github.com/influxdata/platform"
"github.com/influxdata/platform/kit/errors" kerrors "github.com/influxdata/platform/kit/errors"
"github.com/julienschmidt/httprouter" "github.com/julienschmidt/httprouter"
) )
// UserHandler represents an HTTP API handler for users. // UserHandler represents an HTTP API handler for users.
type UserHandler struct { type UserHandler struct {
*httprouter.Router *httprouter.Router
UserService platform.UserService UserService platform.UserService
} }
@ -40,17 +39,17 @@ func (h *UserHandler) handlePostUser(w http.ResponseWriter, r *http.Request) {
req, err := decodePostUserRequest(ctx, r) req, err := decodePostUserRequest(ctx, r)
if err != nil { if err != nil {
errors.EncodeHTTP(ctx, err, w) kerrors.EncodeHTTP(ctx, err, w)
return return
} }
if err := h.UserService.CreateUser(ctx, req.User); err != nil { if err := h.UserService.CreateUser(ctx, req.User); err != nil {
errors.EncodeHTTP(ctx, err, w) kerrors.EncodeHTTP(ctx, err, w)
return return
} }
if err := encodeResponse(ctx, w, http.StatusCreated, req.User); err != nil { if err := encodeResponse(ctx, w, http.StatusCreated, req.User); err != nil {
errors.EncodeHTTP(ctx, err, w) kerrors.EncodeHTTP(ctx, err, w)
return return
} }
} }
@ -76,18 +75,18 @@ func (h *UserHandler) handleGetUser(w http.ResponseWriter, r *http.Request) {
req, err := decodeGetUserRequest(ctx, r) req, err := decodeGetUserRequest(ctx, r)
if err != nil { if err != nil {
errors.EncodeHTTP(ctx, err, w) kerrors.EncodeHTTP(ctx, err, w)
return return
} }
b, err := h.UserService.FindUserByID(ctx, req.UserID) b, err := h.UserService.FindUserByID(ctx, req.UserID)
if err != nil { if err != nil {
errors.EncodeHTTP(ctx, err, w) kerrors.EncodeHTTP(ctx, err, w)
return return
} }
if err := encodeResponse(ctx, w, http.StatusOK, b); err != nil { if err := encodeResponse(ctx, w, http.StatusOK, b); err != nil {
errors.EncodeHTTP(ctx, err, w) kerrors.EncodeHTTP(ctx, err, w)
return return
} }
} }
@ -100,7 +99,7 @@ func decodeGetUserRequest(ctx context.Context, r *http.Request) (*getUserRequest
params := httprouter.ParamsFromContext(ctx) params := httprouter.ParamsFromContext(ctx)
id := params.ByName("id") id := params.ByName("id")
if id == "" { if id == "" {
return nil, errors.InvalidDataf("url missing id") return nil, kerrors.InvalidDataf("url missing id")
} }
var i platform.ID var i platform.ID
@ -121,12 +120,12 @@ func (h *UserHandler) handleDeleteUser(w http.ResponseWriter, r *http.Request) {
req, err := decodeDeleteUserRequest(ctx, r) req, err := decodeDeleteUserRequest(ctx, r)
if err != nil { if err != nil {
errors.EncodeHTTP(ctx, err, w) kerrors.EncodeHTTP(ctx, err, w)
return return
} }
if err := h.UserService.DeleteUser(ctx, req.UserID); err != nil { if err := h.UserService.DeleteUser(ctx, req.UserID); err != nil {
errors.EncodeHTTP(ctx, err, w) kerrors.EncodeHTTP(ctx, err, w)
return return
} }
@ -141,7 +140,7 @@ func decodeDeleteUserRequest(ctx context.Context, r *http.Request) (*deleteUserR
params := httprouter.ParamsFromContext(ctx) params := httprouter.ParamsFromContext(ctx)
id := params.ByName("id") id := params.ByName("id")
if id == "" { if id == "" {
return nil, errors.InvalidDataf("url missing id") return nil, kerrors.InvalidDataf("url missing id")
} }
var i platform.ID var i platform.ID
@ -160,18 +159,18 @@ func (h *UserHandler) handleGetUsers(w http.ResponseWriter, r *http.Request) {
req, err := decodeGetUsersRequest(ctx, r) req, err := decodeGetUsersRequest(ctx, r)
if err != nil { if err != nil {
errors.EncodeHTTP(ctx, err, w) kerrors.EncodeHTTP(ctx, err, w)
return return
} }
users, _, err := h.UserService.FindUsers(ctx, req.filter) users, _, err := h.UserService.FindUsers(ctx, req.filter)
if err != nil { if err != nil {
errors.EncodeHTTP(ctx, err, w) kerrors.EncodeHTTP(ctx, err, w)
return return
} }
if err := encodeResponse(ctx, w, http.StatusOK, users); err != nil { if err := encodeResponse(ctx, w, http.StatusOK, users); err != nil {
errors.EncodeHTTP(ctx, err, w) kerrors.EncodeHTTP(ctx, err, w)
return return
} }
} }
@ -204,18 +203,18 @@ func (h *UserHandler) handlePatchUser(w http.ResponseWriter, r *http.Request) {
req, err := decodePatchUserRequest(ctx, r) req, err := decodePatchUserRequest(ctx, r)
if err != nil { if err != nil {
errors.EncodeHTTP(ctx, err, w) kerrors.EncodeHTTP(ctx, err, w)
return return
} }
b, err := h.UserService.UpdateUser(ctx, req.UserID, req.Update) b, err := h.UserService.UpdateUser(ctx, req.UserID, req.Update)
if err != nil { if err != nil {
errors.EncodeHTTP(ctx, err, w) kerrors.EncodeHTTP(ctx, err, w)
return return
} }
if err := encodeResponse(ctx, w, http.StatusOK, b); err != nil { if err := encodeResponse(ctx, w, http.StatusOK, b); err != nil {
errors.EncodeHTTP(ctx, err, w) kerrors.EncodeHTTP(ctx, err, w)
return return
} }
} }
@ -229,7 +228,7 @@ func decodePatchUserRequest(ctx context.Context, r *http.Request) (*patchUserReq
params := httprouter.ParamsFromContext(ctx) params := httprouter.ParamsFromContext(ctx)
id := params.ByName("id") id := params.ByName("id")
if id == "" { if id == "" {
return nil, errors.InvalidDataf("url missing id") return nil, kerrors.InvalidDataf("url missing id")
} }
var i platform.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 { 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 var b platform.User
@ -295,7 +294,7 @@ func (s *UserService) FindUser(ctx context.Context, filter platform.UserFilter)
} }
if n == 0 { if n == 0 {
return nil, fmt.Errorf("found no matching user") return nil, errors.New("found no matching user")
} }
return users[0], nil return users[0], nil
@ -332,7 +331,7 @@ func (s *UserService) FindUsers(ctx context.Context, filter platform.UserFilter,
} }
if resp.StatusCode != http.StatusOK { 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 var bs []*platform.User
@ -375,7 +374,7 @@ func (s *UserService) CreateUser(ctx context.Context, u *platform.User) error {
} }
if resp.StatusCode != http.StatusCreated { 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 { 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 { 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 var u platform.User
@ -446,7 +445,7 @@ func (s *UserService) DeleteUser(ctx context.Context, id platform.ID) error {
} }
if resp.StatusCode != http.StatusAccepted { 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 return nil