Skip to content

Commit 74e8d2f

Browse files
Refactor project structure: add MongoDB support, enhance Redis repository, and implement session management; update Makefile and pre-commit hooks.
1 parent 4af8447 commit 74e8d2f

File tree

16 files changed

+255
-173
lines changed

16 files changed

+255
-173
lines changed

.husky/hooks/pre-commit

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/bin/sh
2+
make lint && make format

Makefile

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,21 @@ sync:
55
go mod tidy
66

77
run:
8-
start-redis
8+
@start-docker
99
go run ./cmd/main.go
1010

11-
start-redis:
11+
start-docker:
1212
docker compose up -d
13+
14+
format:
15+
gofmt -s -w .
16+
17+
lint:
18+
# go vet ./...
19+
@command -v golangci-lint >/dev/null 2>&1 \
20+
|| sudo snap install golangci-lint --classic
21+
golangci-lint run
22+
23+
build:
24+
go build ./cmd/main.go
25+

cmd/main.go

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,3 @@
1-
package main
2-
3-
import (
4-
configLoader "github.com/Programmer-RD-AI/auth-forge/config_loader"
5-
)
6-
7-
func main() {
8-
config := configLoader.LoadConfig()
9-
10-
}
1+
package main
2+
3+
func main() {}

config/config.go

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

33
type RedisConfig struct {
4-
Host string
5-
Port int
4+
Host string
5+
Port int
66
Password string
77
Database int
88
}
99

10+
type MongoConfig struct {
11+
Uri string
12+
}
13+
1014
type Config struct {
11-
RedisConfig
15+
RedisConfig
16+
MongoConfig
1217
}

config/config_loader.go

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,16 @@ package config
33
import (
44
"os"
55
"strconv"
6-
"sync"
76

87
"github.com/joho/godotenv"
98
)
109

11-
var (
12-
config *Config
13-
once sync.Once
14-
)
15-
1610
func LoadConfig() *Config {
17-
once.Do(func() {
18-
godotenv.Load()
19-
config = &Config{
20-
RedisConfig: loadRedisConfig(),
21-
}
22-
})
11+
godotenv.Load()
12+
config := &Config{
13+
RedisConfig: loadRedisConfig(),
14+
MongoConfig: loadMongoConfig(),
15+
}
2316
return config
2417
}
2518

@@ -35,6 +28,14 @@ func loadRedisConfig() RedisConfig {
3528
Database: db,
3629
}
3730
}
31+
32+
func loadMongoConfig() MongoConfig {
33+
uri, _ := GetEnv("MONGODB_URI", "mongodb://localhost:27017")
34+
return MongoConfig{
35+
Uri: uri,
36+
}
37+
}
38+
3839
func GetEnv[T string | int](key string, defaultVal T) (T, error) {
3940
rawEnv, ok := os.LookupEnv(key)
4041
if !ok {

docker-compose.yml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,22 @@ version: "3.8"
22

33
services:
44
redis:
5-
image: redis:6-alphine
5+
image: redis:8.0-alphine
66
container_name: auth-redis
77
ports:
88
- "6379:6379"
99
volumes:
1010
- redis-data:/data
1111

12+
mongodb:
13+
image: mongo:8.0.12-rc0
14+
container_name: auth-mongo
15+
ports:
16+
- "27017:27017"
17+
volumes:
18+
- mongo-data:/data/db
19+
1220
volumes:
1321
redis-data: {}
22+
mongo-data: {}
23+

go.mod

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@ 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+
)
9+
510
require (
611
github.com/cespare/xxhash/v2 v2.3.0 // indirect
712
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
8-
github.com/joho/godotenv v1.5.1 // indirect
9-
github.com/redis/go-redis/v9 v9.11.0 // indirect
1013
)

go.sum

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
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=
15
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
26
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
37
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78=

internal/session/model.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package session
2+
3+
import (
4+
"time"
5+
)
6+
7+
type Metadata = map[string]any
8+
9+
type Session struct {
10+
SessionID string
11+
ExpireTime time.Duration
12+
SessionValue
13+
}
14+
15+
type SessionValue struct {
16+
UserID string
17+
Metadata Metadata
18+
}

internal/session/repository.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package session
2+
3+
import "github.com/Programmer-RD-AI/auth-forge/internal/store"
4+
5+
6+
type SessionRepository struct {
7+
store.RedisStore
8+
}
9+
10+
func CreateSession() {}
11+
12+
func RefreshSession() {}

0 commit comments

Comments
 (0)