From 7eb3e00b351e41445a97bbf246134fdef84f0ce8 Mon Sep 17 00:00:00 2001 From: jvoisin Date: Mon, 21 Dec 2020 19:39:39 +0100 Subject: [PATCH] Use a couple of defer in internal/home/auth.go --- internal/home/auth.go | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/internal/home/auth.go b/internal/home/auth.go index 00407fa0..941c97ab 100644 --- a/internal/home/auth.go +++ b/internal/home/auth.go @@ -230,16 +230,15 @@ func (a *Auth) CheckSession(sess string) int { update := false a.lock.Lock() + defer a.lock.Unlock() s, ok := a.sessions[sess] if !ok { - a.lock.Unlock() return -1 } if s.expire <= now { delete(a.sessions, sess) key, _ := hex.DecodeString(sess) a.removeSession(key) - a.lock.Unlock() return 1 } @@ -250,8 +249,6 @@ func (a *Auth) CheckSession(sess string) int { s.expire = newExpire } - a.lock.Unlock() - if update { key, _ := hex.DecodeString(sess) if a.storeSession(key, s) { @@ -517,18 +514,16 @@ func (a *Auth) GetCurrentUser(r *http.Request) User { } a.lock.Lock() + defer a.lock.Unlock() s, ok := a.sessions[cookie.Value] if !ok { - a.lock.Unlock() return User{} } for _, u := range a.users { if u.Name == s.userName { - a.lock.Unlock() return u } } - a.lock.Unlock() return User{} }