Skip to content

Commit 81b2b5a

Browse files
Refactor session management: remove Redis configuration and related code, introduce BaseStore interface, and restructure session models; update session service and repository implementations.
1 parent 501fcf6 commit 81b2b5a

File tree

14 files changed

+197
-162
lines changed

14 files changed

+197
-162
lines changed

archive/redis.go

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
// package store
2+
3+
// import (
4+
// "context"
5+
// "fmt"
6+
// "time"
7+
8+
// "github.com/Programmer-RD-AI/auth-forge/config"
9+
// "github.com/Programmer-RD-AI/auth-forge/pkg/authforge"
10+
// "github.com/redis/go-redis/v9"
11+
// )
12+
13+
// const (
14+
// defaultExpire time.Duration = 0 * time.Second
15+
// providerName = "redis"
16+
// )
17+
18+
// type RedisStore struct {
19+
// name string
20+
// config config.RedisConfig
21+
// client *redis.Client
22+
// ctx context.Context
23+
// }
24+
25+
// func NewRedisStore(config config.RedisConfig) *RedisStore {
26+
// return &RedisStore{
27+
// name: providerName,
28+
// config: config,
29+
// client: nil,
30+
// ctx: nil,
31+
// }
32+
// }
33+
34+
// func (r *RedisStore) Connect() {
35+
// redisClient := redis.NewClient(createRedisOption(&r.config))
36+
// initCtx := context.Background()
37+
// r.client = redisClient
38+
// r.ctx = initCtx
39+
// }
40+
41+
// func (r *RedisStore) HealthCheck() (bool, error) {
42+
// if err := r.client.Ping(r.ctx).Err(); err != nil {
43+
// return false, authforge.NewDbHealthCheckFail(r.name, fmt.Sprintf("Failed to connect to Redis: %v", err))
44+
// }
45+
// return true, nil
46+
// }
47+
48+
// func (r *RedisStore) Read(key string) (string, error) {
49+
// val, err := r.client.Get(r.ctx, key).Result()
50+
// if err == redis.Nil {
51+
// return "", authforge.NewKeyDoesNotExistError(key)
52+
// } else if err != nil {
53+
// return "", err
54+
// } else {
55+
// return val, nil
56+
// }
57+
// }
58+
59+
// func (r *RedisStore) Close() bool {
60+
// if err := r.client.Close(); err != nil {
61+
// return false
62+
// }
63+
// return true
64+
// }
65+
66+
// func (r *RedisStore) Create(key string, value string, TTL *int) bool {
67+
// var expire time.Duration
68+
// if TTL != nil {
69+
// expire = time.Duration(*TTL) * time.Second
70+
// } else {
71+
// expire = defaultExpire
72+
// }
73+
// if err := r.client.Set(r.ctx, key, &value, expire).Err(); err != nil {
74+
// fmt.Println("Error creating key:", err)
75+
// return true
76+
// }
77+
// return false
78+
// }
79+
80+
// func (r *RedisStore) Delete(key string) (int64, error) {
81+
// deleted, err := r.client.Del(r.ctx, key).Result()
82+
// if err != nil {
83+
// return 0, err
84+
// }
85+
// return deleted, nil
86+
// }
87+
88+
// func (r *RedisStore) Update(key string, value *any) bool {
89+
// if err := r.client.Set(r.ctx, key, value, 0).Err(); err != nil {
90+
// return false
91+
// }
92+
// return true
93+
// }
94+
95+
// func createRedisOption(redisConfig *config.RedisConfig) *redis.Options {
96+
// return &redis.Options{
97+
// Addr: fmt.Sprintf("%s:%d", redisConfig.Host, redisConfig.Port),
98+
// Password: redisConfig.Password,
99+
// DB: redisConfig.Database,
100+
// }
101+
// }

config/config.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,9 @@
11
package config
22

3-
type RedisConfig struct {
4-
Host string
5-
Port int
6-
Password string
7-
Database int
8-
}
9-
103
type MongoConfig struct {
114
Uri string
125
}
136

147
type Config struct {
15-
RedisConfig
168
MongoConfig
179
}

config/config_loader.go

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,12 @@ import (
1010
func LoadConfig() *Config {
1111
godotenv.Load()
1212
config := &Config{
13-
RedisConfig: loadRedisConfig(),
1413
MongoConfig: loadMongoConfig(),
1514
}
1615
return config
1716
}
1817

19-
func loadRedisConfig() RedisConfig {
20-
h, _ := GetEnv("REDIS_HOST", "localhost")
21-
p, _ := GetEnv("REDIS_PORT", 6379)
22-
pass, _ := GetEnv("REDIS_PASSWORD", "")
23-
db, _ := GetEnv("REDIS_DATABASE", 0)
24-
return RedisConfig{
25-
Host: h,
26-
Port: p,
27-
Password: pass,
28-
Database: db,
29-
}
30-
}
18+
3119

3220
func loadMongoConfig() MongoConfig {
3321
uri, _ := GetEnv("MONGODB_URI", "mongodb://localhost:27017")

docker-compose.yml

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,6 @@
11
version: "3.8"
22

33
services:
4-
redis:
5-
image: redis:8.0-alphine
6-
container_name: auth-redis
7-
ports:
8-
- "6379:6379"
9-
volumes:
10-
- redis-data:/data
11-
124
mongodb:
135
image: mongo:8.0.12-rc0
146
container_name: auth-mongo
@@ -18,6 +10,5 @@ services:
1810
- mongo-data:/data/db
1911

2012
volumes:
21-
redis-data: {}
2213
mongo-data: {}
2314

go.mod

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

33
go 1.24.4
44

5-
require (
6-
github.com/joho/godotenv v1.5.1
7-
github.com/redis/go-redis/v9 v9.11.0
8-
)
5+
require github.com/joho/godotenv v1.5.1
96

107
require (
11-
github.com/cespare/xxhash/v2 v2.3.0 // indirect
12-
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
8+
github.com/golang/snappy v1.0.0 // indirect
9+
github.com/klauspost/compress v1.16.7 // indirect
10+
github.com/xdg-go/pbkdf2 v1.0.0 // indirect
11+
github.com/xdg-go/scram v1.1.2 // indirect
12+
github.com/xdg-go/stringprep v1.0.4 // indirect
13+
github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78 // indirect
14+
go.mongodb.org/mongo-driver/v2 v2.2.2 // indirect
15+
golang.org/x/crypto v0.33.0 // indirect
16+
golang.org/x/sync v0.11.0 // indirect
17+
golang.org/x/text v0.22.0 // indirect
1318
)

go.sum

Lines changed: 44 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,46 @@
1-
github.com/bsm/ginkgo/v2 v2.12.0 h1:Ny8MWAHyOepLGlLKYmXG4IEkioBysk6GpaRTLC8zwWs=
2-
github.com/bsm/ginkgo/v2 v2.12.0/go.mod h1:SwYbGRRDovPVboqFv0tPTcG1sN61LM1Z4ARdbAV9g4c=
3-
github.com/bsm/gomega v1.27.10 h1:yeMWxP2pV2fG3FgAODIY8EiRE3dy0aeFYt4l7wh6yKA=
4-
github.com/bsm/gomega v1.27.10/go.mod h1:JyEr/xRbxbtgWNi8tIEVPUYZ5Dzef52k01W3YH0H+O0=
5-
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
6-
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
7-
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78=
8-
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc=
1+
github.com/golang/snappy v1.0.0 h1:Oy607GVXHs7RtbggtPBnr2RmDArIsAefDwvrdWvRhGs=
2+
github.com/golang/snappy v1.0.0/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
93
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
104
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
11-
github.com/redis/go-redis/v9 v9.11.0 h1:E3S08Gl/nJNn5vkxd2i78wZxWAPNZgUNTp8WIJUAiIs=
12-
github.com/redis/go-redis/v9 v9.11.0/go.mod h1:huWgSWd8mW6+m0VPhJjSSQ+d6Nh1VICQ6Q5lHuCH/Iw=
5+
github.com/klauspost/compress v1.16.7 h1:2mk3MPGNzKyxErAw8YaohYh69+pa4sIQSC0fPGCFR9I=
6+
github.com/klauspost/compress v1.16.7/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE=
7+
github.com/xdg-go/pbkdf2 v1.0.0 h1:Su7DPu48wXMwC3bs7MCNG+z4FhcyEuz5dlvchbq0B0c=
8+
github.com/xdg-go/pbkdf2 v1.0.0/go.mod h1:jrpuAogTd400dnrH08LKmI/xc1MbPOebTwRqcT5RDeI=
9+
github.com/xdg-go/scram v1.1.2 h1:FHX5I5B4i4hKRVRBCFRxq1iQRej7WO3hhBuJf+UUySY=
10+
github.com/xdg-go/scram v1.1.2/go.mod h1:RT/sEzTbU5y00aCK8UOx6R7YryM0iF1N2MOmC3kKLN4=
11+
github.com/xdg-go/stringprep v1.0.4 h1:XLI/Ng3O1Atzq0oBs3TWm+5ZVgkq2aqdlvP9JtoZ6c8=
12+
github.com/xdg-go/stringprep v1.0.4/go.mod h1:mPGuuIYwz7CmR2bT9j4GbQqutWS1zV24gijq1dTyGkM=
13+
github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78 h1:ilQV1hzziu+LLM3zUTJ0trRztfwgjqKnBWNtSRkbmwM=
14+
github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78/go.mod h1:aL8wCCfTfSfmXjznFBSZNN13rSJjlIOI1fUNAtF7rmI=
15+
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
16+
go.mongodb.org/mongo-driver/v2 v2.2.2 h1:9cYuS3fl1Xhqwpfazso10V7BHQD58kCgtzhfAmJYz9c=
17+
go.mongodb.org/mongo-driver/v2 v2.2.2/go.mod h1:qQkDMhCGWl3FN509DfdPd4GRBLU/41zqF/k8eTRceps=
18+
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
19+
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
20+
golang.org/x/crypto v0.33.0 h1:IOBPskki6Lysi0lo9qQvbxiQ+FvsCC/YWOecCHAixus=
21+
golang.org/x/crypto v0.33.0/go.mod h1:bVdXmD7IV/4GdElGPozy6U7lWdRXA4qyRVGJV57uQ5M=
22+
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
23+
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
24+
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
25+
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
26+
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
27+
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
28+
golang.org/x/sync v0.11.0 h1:GGz8+XQP4FvTTrjZPzNKTMFtSXH80RAzG+5ghFPgK9w=
29+
golang.org/x/sync v0.11.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
30+
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
31+
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
32+
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
33+
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
34+
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
35+
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
36+
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
37+
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
38+
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
39+
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
40+
golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ=
41+
golang.org/x/text v0.22.0 h1:bofq7m3/HAFvbF51jz3Q9wLg3jkvSPuiZu/pD1XwgtM=
42+
golang.org/x/text v0.22.0/go.mod h1:YRoo4H8PVmsu+E3Ou7cqLVH8oXWIHVoX0jqUWALQhfY=
43+
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
44+
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
45+
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
46+
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=

internal/session/model.go renamed to internal/model/session.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package session
1+
package model
22

33
import (
44
"time"
@@ -16,3 +16,5 @@ type SessionValue struct {
1616
UserID string
1717
Metadata Metadata
1818
}
19+
20+

internal/model/store.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package model
2+
3+
type BaseStore interface {
4+
Connect()
5+
Create()
6+
Read()
7+
Update()
8+
Delete()
9+
Close()
10+
}

internal/session/repository.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
package session
22

3-
import "github.com/Programmer-RD-AI/auth-forge/internal/store"
4-
3+
import "github.com/Programmer-RD-AI/auth-forge/internal/model"
54

65
type SessionRepository struct {
7-
store.RedisStore
6+
store model.BaseStore
87
}
98

10-
func CreateSession() {}
11-
12-
func RefreshSession() {}
9+
func NewSessionRepository(store model.BaseStore) SessionRepository {
10+
return SessionRepository{
11+
store: nil,
12+
}
13+
}

internal/session/service.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,17 @@
11
package session
2+
3+
4+
type SessionService struct {
5+
sessionRepository *SessionRepository
6+
}
7+
8+
func NewSessionService(repo *SessionRepository) SessionService{
9+
return SessionService{
10+
sessionRepository: repo,
11+
}
12+
}
13+
14+
15+
func (s *SessionService) CreateSession(){
16+
17+
}

0 commit comments

Comments
 (0)