Skip to content

Commit 4af8447

Browse files
Merge pull request #3 from Programmer-RD-AI/feat/register-user
Add initial project structure with Redis repository implementation an…
2 parents b14b602 + a38f0cb commit 4af8447

File tree

13 files changed

+469
-215
lines changed

13 files changed

+469
-215
lines changed

.example.env

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
REDIS_HOST=localhost
2+
REDIS_PORT=6379
3+
REDIS_PASSWORD=
4+
REDIS_DATABASE=0

LICENSE

Lines changed: 201 additions & 201 deletions
Large diffs are not rendered by default.

Makefile

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1-
name := auth-forge
2-
version := 0.1.0
3-
4-
sync:
5-
go mod tidy
6-
7-
run:
8-
go run ./cmd/main.go
1+
name := auth-forge
2+
version := 0.1.0
3+
4+
sync:
5+
go mod tidy
6+
7+
run:
8+
start-redis
9+
go run ./cmd/main.go
10+
11+
start-redis:
12+
docker compose up -d

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
# auth-forge
2-
3-
A self-hosted, provider-agnostic authentication library offering email/password and anonymous login flows, JWT issuance & rotation, session management, and role-based access control (RBAC).
1+
# auth-forge
2+
3+
A self-hosted, authentication library offering email/password and anonymous login flows, JWT issuance & rotation, session management, and role-based access control (RBAC).

cmd/main.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1-
package main
2-
3-
func main() {}
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+
}

config/config.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package config
2+
3+
type RedisConfig struct {
4+
Host string
5+
Port int
6+
Password string
7+
Database int
8+
}
9+
10+
type Config struct {
11+
RedisConfig
12+
}

config/config_loader.go

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package config
2+
3+
import (
4+
"os"
5+
"strconv"
6+
"sync"
7+
8+
"github.com/joho/godotenv"
9+
)
10+
11+
var (
12+
config *Config
13+
once sync.Once
14+
)
15+
16+
func LoadConfig() *Config {
17+
once.Do(func() {
18+
godotenv.Load()
19+
config = &Config{
20+
RedisConfig: loadRedisConfig(),
21+
}
22+
})
23+
return config
24+
}
25+
26+
func loadRedisConfig() RedisConfig {
27+
h, _ := GetEnv("REDIS_HOST", "localhost")
28+
p, _ := GetEnv("REDIS_PORT", 6379)
29+
pass, _ := GetEnv("REDIS_PASSWORD", "")
30+
db, _ := GetEnv("REDIS_DATABASE", 0)
31+
return RedisConfig{
32+
Host: h,
33+
Port: p,
34+
Password: pass,
35+
Database: db,
36+
}
37+
}
38+
func GetEnv[T string | int](key string, defaultVal T) (T, error) {
39+
rawEnv, ok := os.LookupEnv(key)
40+
if !ok {
41+
return defaultVal, nil
42+
}
43+
var ret any
44+
switch any(defaultVal).(type) {
45+
case string:
46+
ret = rawEnv
47+
case int:
48+
intVal, err := strconv.Atoi(rawEnv)
49+
if err != nil {
50+
return defaultVal, err
51+
}
52+
ret = intVal
53+
54+
}
55+
return ret.(T), nil
56+
}

docker-compose.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
version: "3.8"
2+
3+
services:
4+
redis:
5+
image: redis:6-alphine
6+
container_name: auth-redis
7+
ports:
8+
- "6379:6379"
9+
volumes:
10+
- redis-data:/data
11+
12+
volumes:
13+
redis-data: {}

go.mod

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
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/joho/godotenv v1.5.1 // indirect
9+
github.com/redis/go-redis/v9 v9.11.0 // indirect
10+
)

go.sum

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
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/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
6+
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
7+
github.com/redis/go-redis/v9 v9.11.0 h1:E3S08Gl/nJNn5vkxd2i78wZxWAPNZgUNTp8WIJUAiIs=
8+
github.com/redis/go-redis/v9 v9.11.0/go.mod h1:huWgSWd8mW6+m0VPhJjSSQ+d6Nh1VICQ6Q5lHuCH/Iw=

0 commit comments

Comments
 (0)