Skip to content

Commit 584a718

Browse files
Add initial project structure with Redis repository implementation and environment variable helper
1 parent b14b602 commit 584a718

File tree

5 files changed

+70
-0
lines changed

5 files changed

+70
-0
lines changed

go.mod

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
11
module github.com/Programmer-RD-AI/auth-forge
22

33
go 1.24.4
4+
5+
require (
6+
github.com/cespare/xxhash/v2 v2.3.0 // indirect
7+
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
8+
github.com/redis/go-redis/v9 v9.11.0 // indirect
9+
)

go.sum

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
2+
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
3+
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78=
4+
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc=
5+
github.com/redis/go-redis/v9 v9.11.0 h1:E3S08Gl/nJNn5vkxd2i78wZxWAPNZgUNTp8WIJUAiIs=
6+
github.com/redis/go-redis/v9 v9.11.0/go.mod h1:huWgSWd8mW6+m0VPhJjSSQ+d6Nh1VICQ6Q5lHuCH/Iw=

helper.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package authforge
2+
3+
import (
4+
"os"
5+
"strconv"
6+
)
7+
8+
func getEnv(key string, defaultVal any) any {
9+
rawEnv, ok := os.LookupEnv(key)
10+
if !ok{
11+
return defaultVal
12+
}
13+
if intEnv, err := strconv.Atoi(rawEnv); err == nil {
14+
return intEnv
15+
}
16+
return rawEnv;
17+
}
18+

shared/repository/redis.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package repository
2+
3+
import "github.com/go-redis/redis/v9"
4+
5+
type RedisConfiguration struct {
6+
Host string
7+
Port int
8+
Password string
9+
Database int
10+
}
11+
12+
type RedisRepository struct {
13+
config RedisConfiguration
14+
client *redis.Client
15+
}
16+
17+
func CreateRedisConfiguration(host *string, port *int, password *string, database *int){}
18+
19+
func (r *RedisReppository) Connect(){
20+
return redis.NewClient(createRedisOption(r.config));
21+
}
22+
23+
func createRedisOption(redisConfig *RedisConfiguration) *redis.Options {
24+
return &redis.Options{
25+
Addr: fmt.Sprintf("%s:%d", redisConfig.Host, redisConfig.Port)
26+
Password: redisConfig.Password
27+
DB: redisConfig.Database
28+
}
29+
}

shared/repository/repository.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package repository
2+
3+
type Repository interface {
4+
Connect() (any, error)
5+
Create(data any) (any, error)
6+
Read(id string) (any, error)
7+
Update(id string, data any) (any, error)
8+
Delete(id string) error
9+
Close() error
10+
}
11+

0 commit comments

Comments
 (0)