From ed336fe39ab16c09354f837a1a326afc44e3a540 Mon Sep 17 00:00:00 2001 From: Peter Stuifzand Date: Mon, 13 May 2019 21:57:07 +0200 Subject: [PATCH] Extract method httpSessionLogout --- cmd/eksterd/http.go | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/cmd/eksterd/http.go b/cmd/eksterd/http.go index 1015120..ea23800 100644 --- a/cmd/eksterd/http.go +++ b/cmd/eksterd/http.go @@ -538,19 +538,7 @@ func (h *mainHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { return } else if r.URL.Path == "/session/logout" { - c, err := r.Cookie("session") - - if err == http.ErrNoCookie { - http.Redirect(w, r, "/", 302) - return - } - - if err == nil { - sessionVar := c.Value - _, _ = conn.Do("DEL", "session:"+sessionVar) - } - - http.Redirect(w, r, "/", 302) + httpSessionLogout(r, w, conn) return } else if r.URL.Path == "/auth/approve" { // create a code @@ -681,3 +669,16 @@ func (h *mainHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { http.NotFound(w, r) } + +func httpSessionLogout(r *http.Request, w http.ResponseWriter, conn redis.Conn) { + c, err := r.Cookie("session") + if err == http.ErrNoCookie { + http.Redirect(w, r, "/", 302) + return + } + if err == nil { + sessionVar := c.Value + _, _ = conn.Do("DEL", "session:"+sessionVar) + } + http.Redirect(w, r, "/", 302) +}