From 246ce98dc8a7a55c6a9dfb850afcc69c7c8ea4f8 Mon Sep 17 00:00:00 2001 From: Guillaume Horel Date: Sat, 10 Jun 2017 19:21:54 -0400 Subject: do not ignore error --- utils.go | 22 +++++++++++++--------- web.go | 4 +++- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/utils.go b/utils.go index 2a47905..901a7d2 100644 --- a/utils.go +++ b/utils.go @@ -34,16 +34,20 @@ func (app *App) GetCookie(r *http.Request, name string, dst interface{}) error { return app.CookieHandler.Decode(name, cookie.Value, dst) } -func (app *App) SetCookie(w http.ResponseWriter, name string, v interface{}, exp int) { - encoded, _ := app.CookieHandler.Encode(name, v) - cookie := &http.Cookie{ - Name: name, - Value: encoded, - Path: "/", - HttpOnly: true, - MaxAge: exp, +func (app *App) SetCookie(w http.ResponseWriter, name string, v interface{}, exp int) error { + if encoded, err := app.CookieHandler.Encode(name, v); err != nil { + return err + } else { + cookie := &http.Cookie{ + Name: name, + Value: encoded, + Path: "/", + HttpOnly: true, + MaxAge: exp, + } + http.SetCookie(w, cookie) + return nil } - http.SetCookie(w, cookie) } func ago(t time.Time) string { diff --git a/web.go b/web.go index 032e04a..43d3c9f 100644 --- a/web.go +++ b/web.go @@ -26,7 +26,9 @@ type UserSession struct { func (app *App) login(w http.ResponseWriter, r *http.Request) { state := hex.EncodeToString(genKey(32)) - app.SetCookie(w, "state", state, 120) + if err := app.SetCookie(w, "state", state, 120); err != nil { + log.Panic(err) + } url := app.Config.OAuth.AuthCodeURL(state) app.Template.ExecuteTemplate(w, "login.tmpl", url) } -- cgit v1.2.3-70-g09d2