Use a couple of defer in internal/home/auth.go

This commit is contained in:
jvoisin 2020-12-21 19:39:39 +01:00
parent bdff46ec1d
commit 7eb3e00b35

View File

@ -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{}
}