Changing struct naming for redis structs
Signed-off-by: Ethan Wellenreiter <ewellenreiter@gmail.com>
This commit is contained in:
parent
22837e8186
commit
31ef839226
@ -15,13 +15,13 @@ import (
|
||||
|
||||
// should be set by the hasher
|
||||
|
||||
type redisCSRF struct {
|
||||
type RedisCSRFStore struct {
|
||||
rdb *redis.Client
|
||||
hasher lcrypto.Hasher
|
||||
expirationTime uint
|
||||
}
|
||||
|
||||
func (r *redisCSRF) AddCSRF(ctx context.Context, sessionToken string) (csrftoken string, err error) {
|
||||
func (r *RedisCSRFStore) AddCSRF(ctx context.Context, sessionToken string) (csrftoken string, err error) {
|
||||
csrf, err := r.hasher.Hash(sessionToken)
|
||||
if err != nil {
|
||||
return "", err
|
||||
@ -34,12 +34,12 @@ func (r *redisCSRF) AddCSRF(ctx context.Context, sessionToken string) (csrftoken
|
||||
return csrftoken, nil
|
||||
}
|
||||
|
||||
func (r *redisCSRF) RemoveCSRF(ctx context.Context, sessionToken string) error {
|
||||
func (r *RedisCSRFStore) RemoveCSRF(ctx context.Context, sessionToken string) error {
|
||||
r.rdb.Del(ctx, sessionToken)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *redisCSRF) ValidCSRF(ctx context.Context, sessionToken string, csrfToken string) (bool, error) {
|
||||
func (r *RedisCSRFStore) ValidCSRF(ctx context.Context, sessionToken string, csrfToken string) (bool, error) {
|
||||
storedcsrfToken, err := r.rdb.Get(ctx, sessionToken).Result()
|
||||
if err != nil {
|
||||
return false, err
|
||||
|
||||
@ -15,13 +15,13 @@ import (
|
||||
|
||||
// should be set by the hasher
|
||||
|
||||
type redisSession struct {
|
||||
type RedisSessionStore struct {
|
||||
rdb *redis.Client
|
||||
sessionTokenLength uint
|
||||
expirationTime uint
|
||||
}
|
||||
|
||||
func (r *redisSession) AddSession(ctx context.Context, userid int64) (token string, err error) {
|
||||
func (r *RedisSessionStore) AddSession(ctx context.Context, userid int64) (token string, err error) {
|
||||
temp, err := lcrypto.GenerateRandomBytes(r.sessionTokenLength)
|
||||
if err != nil {
|
||||
return "", err
|
||||
@ -35,7 +35,7 @@ func (r *redisSession) AddSession(ctx context.Context, userid int64) (token stri
|
||||
return token, err
|
||||
}
|
||||
|
||||
func (r *redisSession) GetSession(ctx context.Context, token string) (valid bool, userid int64, err error) { // should also extend it by the lifespan if near the end of the time. maybe a 5 min window at the end?
|
||||
func (r *RedisSessionStore) GetSession(ctx context.Context, token string) (valid bool, userid int64, err error) { // should also extend it by the lifespan if near the end of the time. maybe a 5 min window at the end?
|
||||
userid, err = r.rdb.Get(ctx, token).Int64()
|
||||
if err == redis.Nil {
|
||||
valid = false
|
||||
@ -54,6 +54,6 @@ func (r *redisSession) GetSession(ctx context.Context, token string) (valid bool
|
||||
return valid, userid, err
|
||||
}
|
||||
|
||||
func (r *redisSession) RemoveSession(ctx context.Context, token string) error {
|
||||
func (r *RedisSessionStore) RemoveSession(ctx context.Context, token string) error {
|
||||
return r.rdb.Del(ctx, token).Err()
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user