Skip to content

Commit 8dd1b87

Browse files
Refactor project to remove Redis support, implement MongoDB integration, and restructure session management; update configuration, repository, and service layers.
1 parent 81b2b5a commit 8dd1b87

File tree

16 files changed

+90
-42
lines changed

16 files changed

+90
-42
lines changed

.example.env

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1 @@
1-
REDIS_HOST=localhost
2-
REDIS_PORT=6379
3-
REDIS_PASSWORD=
4-
REDIS_DATABASE=0
1+
MONGODB_URI=mongodb://localhost:27017
File renamed without changes.

config/config_loader.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ func LoadConfig() *Config {
1515
return config
1616
}
1717

18-
19-
2018
func loadMongoConfig() MongoConfig {
2119
uri, _ := GetEnv("MONGODB_URI", "mongodb://localhost:27017")
2220
return MongoConfig{

go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@ require github.com/joho/godotenv v1.5.1
77
require (
88
github.com/golang/snappy v1.0.0 // indirect
99
github.com/klauspost/compress v1.16.7 // indirect
10+
github.com/montanaflynn/stats v0.7.1 // indirect
1011
github.com/xdg-go/pbkdf2 v1.0.0 // indirect
1112
github.com/xdg-go/scram v1.1.2 // indirect
1213
github.com/xdg-go/stringprep v1.0.4 // indirect
1314
github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78 // indirect
15+
go.mongodb.org/mongo-driver v1.17.4 // indirect
1416
go.mongodb.org/mongo-driver/v2 v2.2.2 // indirect
1517
golang.org/x/crypto v0.33.0 // indirect
1618
golang.org/x/sync v0.11.0 // indirect

go.sum

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
44
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
55
github.com/klauspost/compress v1.16.7 h1:2mk3MPGNzKyxErAw8YaohYh69+pa4sIQSC0fPGCFR9I=
66
github.com/klauspost/compress v1.16.7/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE=
7+
github.com/montanaflynn/stats v0.7.1 h1:etflOAAHORrCC44V+aR6Ftzort912ZU+YLiSTuV8eaE=
8+
github.com/montanaflynn/stats v0.7.1/go.mod h1:etXPPgVO6n31NxCd9KQUMvCM+ve0ruNzt6R8Bnaayow=
79
github.com/xdg-go/pbkdf2 v1.0.0 h1:Su7DPu48wXMwC3bs7MCNG+z4FhcyEuz5dlvchbq0B0c=
810
github.com/xdg-go/pbkdf2 v1.0.0/go.mod h1:jrpuAogTd400dnrH08LKmI/xc1MbPOebTwRqcT5RDeI=
911
github.com/xdg-go/scram v1.1.2 h1:FHX5I5B4i4hKRVRBCFRxq1iQRej7WO3hhBuJf+UUySY=
@@ -13,6 +15,8 @@ github.com/xdg-go/stringprep v1.0.4/go.mod h1:mPGuuIYwz7CmR2bT9j4GbQqutWS1zV24gi
1315
github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78 h1:ilQV1hzziu+LLM3zUTJ0trRztfwgjqKnBWNtSRkbmwM=
1416
github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78/go.mod h1:aL8wCCfTfSfmXjznFBSZNN13rSJjlIOI1fUNAtF7rmI=
1517
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
18+
go.mongodb.org/mongo-driver v1.17.4 h1:jUorfmVzljjr0FLzYQsGP8cgN/qzzxlY9Vh0C9KFXVw=
19+
go.mongodb.org/mongo-driver v1.17.4/go.mod h1:Hy04i7O2kC4RS06ZrhPRqj/u4DTYkFDAAccj+rVKqgQ=
1620
go.mongodb.org/mongo-driver/v2 v2.2.2 h1:9cYuS3fl1Xhqwpfazso10V7BHQD58kCgtzhfAmJYz9c=
1721
go.mongodb.org/mongo-driver/v2 v2.2.2/go.mod h1:qQkDMhCGWl3FN509DfdPd4GRBLU/41zqF/k8eTRceps=
1822
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=

internal/model/session.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,3 @@ type SessionValue struct {
1616
UserID string
1717
Metadata Metadata
1818
}
19-
20-
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package store
2+
3+
type BaseRepository interface {
4+
Create()
5+
Read()
6+
Update()
7+
Delete()
8+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package store
2+
3+
import (
4+
"context"
5+
6+
"github.com/Programmer-RD-AI/auth-forge/internal/util"
7+
"go.mongodb.org/mongo-driver/mongo"
8+
)
9+
10+
type MongoDBStore struct {
11+
coll *mongo.Collection
12+
model any
13+
}
14+
15+
func HealthCheck(ctx context.Context, client *mongo.Client) bool {
16+
if err := client.Ping(ctx, nil); err != nil {
17+
return false
18+
}
19+
return true
20+
}
21+
22+
func GetCollection(databaseName string, collectionName string, client *mongo.Client) *mongo.Collection {
23+
return client.Database(databaseName).Collection(collectionName)
24+
}
25+
26+
func (m *MongoDBStore) Create(ctx context.Context) (interface{}, error) {
27+
res, err := m.coll.InsertOne(ctx, m.model)
28+
if err != nil {
29+
return nil, err
30+
}
31+
return res.InsertedID, nil
32+
}
33+
34+
func (m *MongoDBStore) Read(ctx context.Context, searchQuery map[string]string, readAll *bool) ([]any, error) {
35+
var final_res []any
36+
filter := util.ConvertToBSON(searchQuery)
37+
38+
}

internal/session/repository.go

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,8 @@ package session
22

33
import "github.com/Programmer-RD-AI/auth-forge/internal/model"
44

5-
type SessionRepository struct {
6-
store model.BaseStore
7-
}
8-
9-
func NewSessionRepository(store model.BaseStore) SessionRepository {
10-
return SessionRepository{
11-
store: nil,
12-
}
5+
type SessionRepository interface {
6+
GetByUserId() *model.Session
7+
GetBySessionId() *model.SessionValue
8+
DeleteSessionId() bool
139
}

internal/session/service.go

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,5 @@
11
package session
22

3-
43
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-
4+
sessionRepository SessionRepository
175
}

0 commit comments

Comments
 (0)