feat/add arangodb support (#80)
*feat: add arangodb init * fix: dao for sql + arangodb * fix: update error logs * fix: use db name dynamically
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
package session
|
||||
|
||||
import (
|
||||
"log"
|
||||
"sync"
|
||||
)
|
||||
|
||||
@@ -30,8 +29,6 @@ func (c *InMemoryStore) AddToken(userId, accessToken, refreshToken string) {
|
||||
c.store[userId] = tempMap
|
||||
}
|
||||
|
||||
log.Println(c.store)
|
||||
|
||||
c.mu.Unlock()
|
||||
}
|
||||
|
||||
@@ -41,7 +38,7 @@ func (c *InMemoryStore) DeleteUserSession(userId string) {
|
||||
c.mu.Unlock()
|
||||
}
|
||||
|
||||
func (c *InMemoryStore) DeleteToken(userId, accessToken string) {
|
||||
func (c *InMemoryStore) DeleteVerificationRequest(userId, accessToken string) {
|
||||
c.mu.Lock()
|
||||
delete(c.store[userId], accessToken)
|
||||
c.mu.Unlock()
|
||||
|
@@ -29,7 +29,7 @@ func (c *RedisStore) DeleteUserSession(userId string) {
|
||||
}
|
||||
}
|
||||
|
||||
func (c *RedisStore) DeleteToken(userId, accessToken string) {
|
||||
func (c *RedisStore) DeleteVerificationRequest(userId, accessToken string) {
|
||||
err := c.store.HDel(c.ctx, "authorizer_"+userId, accessToken).Err()
|
||||
if err != nil {
|
||||
log.Fatalln("Error deleting redis token:", err)
|
||||
@@ -47,7 +47,7 @@ func (c *RedisStore) GetToken(userId, accessToken string) string {
|
||||
token := ""
|
||||
res, err := c.store.HMGet(c.ctx, "authorizer_"+userId, accessToken).Result()
|
||||
if err != nil {
|
||||
log.Println("Error getting token from redis store:", err)
|
||||
log.Println("error getting token from redis store:", err)
|
||||
}
|
||||
if len(res) > 0 && res[0] != nil {
|
||||
token = fmt.Sprintf("%v", res[0])
|
||||
@@ -66,7 +66,7 @@ func (c *RedisStore) GetSocialLoginState(key string) string {
|
||||
state := ""
|
||||
state, err := c.store.Get(c.ctx, key).Result()
|
||||
if err != nil {
|
||||
log.Println("Error getting token from redis store:", err)
|
||||
log.Println("error getting token from redis store:", err)
|
||||
}
|
||||
|
||||
return state
|
||||
|
@@ -27,12 +27,12 @@ func SetToken(userId, accessToken, refreshToken string) {
|
||||
}
|
||||
}
|
||||
|
||||
func DeleteToken(userId, accessToken string) {
|
||||
func DeleteVerificationRequest(userId, accessToken string) {
|
||||
if SessionStoreObj.RedisMemoryStoreObj != nil {
|
||||
SessionStoreObj.RedisMemoryStoreObj.DeleteToken(userId, accessToken)
|
||||
SessionStoreObj.RedisMemoryStoreObj.DeleteVerificationRequest(userId, accessToken)
|
||||
}
|
||||
if SessionStoreObj.InMemoryStoreObj != nil {
|
||||
SessionStoreObj.InMemoryStoreObj.DeleteToken(userId, accessToken)
|
||||
SessionStoreObj.InMemoryStoreObj.DeleteVerificationRequest(userId, accessToken)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -96,7 +96,7 @@ func RemoveSocialLoginState(key string) {
|
||||
|
||||
func InitSession() {
|
||||
if constants.REDIS_URL != "" {
|
||||
log.Println("Using redis store to save sessions")
|
||||
log.Println("using redis store to save sessions")
|
||||
opt, err := redis.ParseURL(constants.REDIS_URL)
|
||||
if err != nil {
|
||||
log.Fatalln("Error parsing redis url:", err)
|
||||
@@ -114,7 +114,7 @@ func InitSession() {
|
||||
}
|
||||
|
||||
} else {
|
||||
log.Println("Using in memory store to save sessions")
|
||||
log.Println("using in memory store to save sessions")
|
||||
SessionStoreObj.InMemoryStoreObj = &InMemoryStore{
|
||||
store: map[string]map[string]string{},
|
||||
socialLoginState: map[string]string{},
|
||||
|
Reference in New Issue
Block a user