-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24 from moonpatel/v-otp
otp verification and some architectural changes
- Loading branch information
Showing
17 changed files
with
312 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package database | ||
|
||
import ( | ||
"context" | ||
"os" | ||
|
||
"github.com/redis/go-redis/v9" | ||
) | ||
|
||
var rdb *RedisService | ||
|
||
type RedisService struct { | ||
RedisClient *redis.Client | ||
Ctx context.Context | ||
} | ||
|
||
func NewRedisClient() *RedisService { | ||
if rdb != nil { | ||
return rdb | ||
} | ||
redisClient := redis.NewClient(&redis.Options{ | ||
Addr: os.Getenv("REDIS_HOST") + ":" + os.Getenv("REDIS_PORT"), | ||
DB: 0, | ||
}) | ||
ctx := context.Background() | ||
|
||
rdb = &RedisService{RedisClient: redisClient, Ctx: ctx} | ||
|
||
return rdb | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package repositories | ||
|
||
import ( | ||
"keizer-auth-api/internal/database" | ||
"time" | ||
) | ||
|
||
type RedisRepository struct { | ||
rds *database.RedisService | ||
} | ||
|
||
func NewRedisRepository(rds *database.RedisService) *RedisRepository { | ||
return &RedisRepository{rds: rds} | ||
} | ||
|
||
func (rr *RedisRepository) Get(key string) (string, error) { | ||
value, err := rr.rds.RedisClient.Get(rr.rds.Ctx, key).Result() | ||
return value, err | ||
} | ||
|
||
// set a key's value with expiration | ||
func (rr *RedisRepository) Set(key string, value string, expiration time.Duration) error { | ||
err := rr.rds.RedisClient.Set(rr.rds.Ctx, key, value, expiration).Err() | ||
return err | ||
} | ||
|
||
func (rr *RedisRepository) TTL(key string) (time.Duration, error) { | ||
result, err := rr.rds.RedisClient.TTL(rr.rds.Ctx, key).Result() | ||
return result, err | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.