JWT proto with login & registration

This commit is contained in:
Mephimeow
2026-06-12 09:12:18 +00:00
committed by zero@thinky
parent ea645860cf
commit 321cba3f9b
14 changed files with 1199 additions and 58 deletions
+50
View File
@@ -0,0 +1,50 @@
package config
import (
"fmt"
"os"
"time"
"github.com/joho/godotenv"
)
type Config struct {
ServerPort string
MongoURI string
MongoDB string
JWTSecret string
JWTExpiration time.Duration
}
func Load() (*Config, error) {
godotenv.Load()
cfg := &Config{
ServerPort: getEnv("SERVER_PORT", "8080"),
MongoURI: getEnv("MONGO_URI", "mongodb://localhost:27017"),
MongoDB: getEnv("MONGO_DB", "aegisguard"),
JWTSecret: getEnv("JWT_SECRET", ""),
JWTExpiration: 24 * time.Hour,
}
if cfg.JWTSecret == "" {
return nil, fmt.Errorf("JWT_SECRET is required in .env file")
}
if expStr := os.Getenv("JWT_EXPIRATION"); expStr != "" {
d, err := time.ParseDuration(expStr)
if err != nil {
return nil, fmt.Errorf("invalid JWT_EXPIRATION: %w", err)
}
cfg.JWTExpiration = d
}
return cfg, nil
}
func getEnv(key, defaultVal string) string {
if val := os.Getenv(key); val != "" {
return val
}
return defaultVal
}