From e76838cc1e4ee912f414ec7711a1f5d1edcebd10 Mon Sep 17 00:00:00 2001 From: Aaron L Date: Sun, 8 May 2016 12:37:02 -0700 Subject: [PATCH] Fix go vet errors --- confirm/confirm.go | 2 +- confirm/confirm_test.go | 2 +- internal/mocks/mocks.go | 4 ++-- internal/response/response.go | 14 +++++++------- recover/recover.go | 10 +++++----- register/register.go | 2 +- 6 files changed, 17 insertions(+), 17 deletions(-) diff --git a/confirm/confirm.go b/confirm/confirm.go index acf4097..9fd40dc 100644 --- a/confirm/confirm.go +++ b/confirm/confirm.go @@ -159,7 +159,7 @@ func (c *Confirm) confirmEmail(to, token string) { func (c *Confirm) confirmHandler(ctx *authboss.Context, w http.ResponseWriter, r *http.Request) error { token := r.FormValue(FormValueConfirm) if len(token) == 0 { - return authboss.ClientDataErr{FormValueConfirm} + return authboss.ClientDataErr{Name: FormValueConfirm} } toHash, err := base64.URLEncoding.DecodeString(token) diff --git a/confirm/confirm_test.go b/confirm/confirm_test.go index 25b27c8..dc7fdab 100644 --- a/confirm/confirm_test.go +++ b/confirm/confirm_test.go @@ -151,7 +151,7 @@ func TestConfirm_ConfirmHandlerErrors(t *testing.T) { Confirmed bool Error error }{ - {"http://localhost", false, authboss.ClientDataErr{FormValueConfirm}}, + {"http://localhost", false, authboss.ClientDataErr{Name: FormValueConfirm}}, {"http://localhost?cnf=c$ats", false, authboss.ErrAndRedirect{Location: "/", Err: errors.New("confirm: token failed to decode \"c$ats\" => illegal base64 data at input byte 1\n")}, }, diff --git a/internal/mocks/mocks.go b/internal/mocks/mocks.go index 8c0fd25..781aa02 100644 --- a/internal/mocks/mocks.go +++ b/internal/mocks/mocks.go @@ -263,12 +263,12 @@ func (m *MockClientStorer) Get(key string) (string, bool) { // GetErr gets a key's value or err if not exist func (m *MockClientStorer) GetErr(key string) (string, error) { if m.GetShouldFail { - return "", authboss.ClientDataErr{key} + return "", authboss.ClientDataErr{Name: key} } v, ok := m.Values[key] if !ok { - return v, authboss.ClientDataErr{key} + return v, authboss.ClientDataErr{Name: key} } return v, nil } diff --git a/internal/response/response.go b/internal/response/response.go index ce43f0e..fcf8f58 100644 --- a/internal/response/response.go +++ b/internal/response/response.go @@ -74,7 +74,7 @@ func LoadTemplates(ab *authboss.Authboss, layout *template.Template, fpath strin func (t Templates) Render(ctx *authboss.Context, w http.ResponseWriter, r *http.Request, name string, data authboss.HTMLData) error { tpl, ok := t[name] if !ok { - return authboss.RenderErr{tpl.Name(), data, ErrTemplateNotFound} + return authboss.RenderErr{TemplateName: tpl.Name(), Data: data, Err: ErrTemplateNotFound} } data.MergeKV( @@ -98,12 +98,12 @@ func (t Templates) Render(ctx *authboss.Context, w http.ResponseWriter, r *http. buffer := &bytes.Buffer{} err := tpl.ExecuteTemplate(buffer, tpl.Name(), data) if err != nil { - return authboss.RenderErr{tpl.Name(), data, err} + return authboss.RenderErr{TemplateName: tpl.Name(), Data: data, Err: ErrTemplateNotFound} } _, err = io.Copy(w, buffer) if err != nil { - return authboss.RenderErr{tpl.Name(), data, err} + return authboss.RenderErr{TemplateName: tpl.Name(), Data: data, Err: ErrTemplateNotFound} } return nil @@ -113,23 +113,23 @@ func (t Templates) Render(ctx *authboss.Context, w http.ResponseWriter, r *http. func Email(mailer authboss.Mailer, email authboss.Email, htmlTpls Templates, nameHTML string, textTpls Templates, namePlain string, data interface{}) error { tplHTML, ok := htmlTpls[nameHTML] if !ok { - return authboss.RenderErr{tplHTML.Name(), data, ErrTemplateNotFound} + return authboss.RenderErr{TemplateName: tplHTML.Name(), Data: data, Err: ErrTemplateNotFound} } tplPlain, ok := textTpls[namePlain] if !ok { - return authboss.RenderErr{tplPlain.Name(), data, ErrTemplateNotFound} + return authboss.RenderErr{TemplateName: tplPlain.Name(), Data: data, Err: ErrTemplateNotFound} } htmlBuffer := &bytes.Buffer{} if err := tplHTML.ExecuteTemplate(htmlBuffer, tplHTML.Name(), data); err != nil { - return authboss.RenderErr{tplHTML.Name(), data, err} + return authboss.RenderErr{TemplateName: tplHTML.Name(), Data: data, Err: err} } email.HTMLBody = htmlBuffer.String() plainBuffer := &bytes.Buffer{} if err := tplPlain.ExecuteTemplate(plainBuffer, tplPlain.Name(), data); err != nil { - return authboss.RenderErr{tplPlain.Name(), data, err} + return authboss.RenderErr{TemplateName: tplPlain.Name(), Data: data, Err: err} } email.TextBody = plainBuffer.String() diff --git a/recover/recover.go b/recover/recover.go index 68e7fc3..5bd380a 100644 --- a/recover/recover.go +++ b/recover/recover.go @@ -151,7 +151,7 @@ func (rec *Recover) startHandlerFunc(ctx *authboss.Context, w http.ResponseWrite // redirect to login when user not found to prevent username sniffing if err := ctx.LoadUser(primaryID); err == authboss.ErrUserNotFound { - return authboss.ErrAndRedirect{err, rec.RecoverOKPath, recoverInitiateSuccessFlash, ""} + return authboss.ErrAndRedirect{Err: err, Location: rec.RecoverOKPath, FlashSuccess: recoverInitiateSuccessFlash} } else if err != nil { return err } @@ -219,9 +219,9 @@ func (r *Recover) completeHandlerFunc(ctx *authboss.Context, w http.ResponseWrit case methodGET: _, err = verifyToken(ctx, req) if err == errRecoveryTokenExpired { - return authboss.ErrAndRedirect{err, "/recover", "", recoverTokenExpiredFlash} + return authboss.ErrAndRedirect{Err: err, Location: "/recover", FlashError: recoverTokenExpiredFlash} } else if err != nil { - return authboss.ErrAndRedirect{err, "/", "", ""} + return authboss.ErrAndRedirect{Err: err, Location: "/"} } token := req.FormValue(formValueToken) @@ -230,7 +230,7 @@ func (r *Recover) completeHandlerFunc(ctx *authboss.Context, w http.ResponseWrit case methodPOST: token := req.FormValue(formValueToken) if len(token) == 0 { - return authboss.ClientDataErr{formValueToken} + return authboss.ClientDataErr{Name: formValueToken} } password := req.FormValue(authboss.StorePassword) @@ -285,7 +285,7 @@ func (r *Recover) completeHandlerFunc(ctx *authboss.Context, w http.ResponseWrit func verifyToken(ctx *authboss.Context, r *http.Request) (attrs authboss.Attributes, err error) { token := r.FormValue(formValueToken) if len(token) == 0 { - return nil, authboss.ClientDataErr{token} + return nil, authboss.ClientDataErr{Name: token} } decoded, err := base64.URLEncoding.DecodeString(token) diff --git a/register/register.go b/register/register.go index 4dc0df2..dcb9d3c 100644 --- a/register/register.go +++ b/register/register.go @@ -93,7 +93,7 @@ func (reg *Register) registerPostHandler(ctx *authboss.Context, w http.ResponseW if user, err := ctx.Storer.Get(key); err != nil && err != authboss.ErrUserNotFound { return err } else if user != nil { - validationErrs = append(validationErrs, authboss.FieldError{reg.PrimaryID, errors.New("Already in use")}) + validationErrs = append(validationErrs, authboss.FieldError{Name: reg.PrimaryID, Err: errors.New("Already in use")}) } if len(validationErrs) != 0 {