Refactor: remove pkg mem cache
This commit is contained in:
@ -5,10 +5,8 @@ import (
|
||||
"crypto/hmac"
|
||||
"crypto/sha256"
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"gralias/models"
|
||||
"gralias/pkg/cache"
|
||||
"gralias/utils"
|
||||
"html/template"
|
||||
"net/http"
|
||||
@ -187,32 +185,5 @@ func makeCookie(username string, remote string) (*http.Cookie, error) {
|
||||
if err := repo.SessionCreate(context.Background(), session); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// set user in session
|
||||
if err := cacheSetSession(sessionToken, session); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return cookie, nil
|
||||
}
|
||||
|
||||
//nolint: unused
|
||||
func cacheGetSession(key string) (*models.Session, error) {
|
||||
userSessionB, err := cache.MemCache.Get(key)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var us *models.Session
|
||||
if err := json.Unmarshal(userSessionB, &us); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return us, nil
|
||||
}
|
||||
|
||||
func cacheSetSession(key string, session *models.Session) error {
|
||||
sesb, err := json.Marshal(session)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
cache.MemCache.Set(key, sesb)
|
||||
cache.MemCache.Expire(key, cfg.SessionLifetime)
|
||||
return nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user