first commit

This commit is contained in:
Beyhan Oğur
2026-04-26 21:37:58 +03:00
commit 8b1fbdee99
104 changed files with 23398 additions and 0 deletions

91
config/config.go Normal file
View File

@@ -0,0 +1,91 @@
package config
import (
"log"
"os"
"strconv"
"github.com/joho/godotenv"
)
type Config struct {
Port string
DBUrl string
JWTSecret string
AppURL string // e.g. https://api.example.com - used for verification links in emails
GoogleClientID string
GoogleClientSecret string
GithubClientID string
GithubClientSecret string
ClientCallbackURL string
RedisUrl string
// Avatar Settings
AvatarHeight int
AvatarWidth int
AvatarQuality int
AvatarFormat string
AvatarMode string // cover, contain, resize
// Email Settings
EmailHost string
EmailPort string
EmailHostUser string
EmailHostPassword string
EmailFrom string
}
var AppConfig *Config
func LoadConfig() {
err := godotenv.Load()
if err != nil {
log.Println("Warning: Error loading .env file, continuing with system env")
}
AppConfig = &Config{
Port: getEnv("PORT", "8080"),
DBUrl: getEnv("DB_URL", ""),
JWTSecret: getEnv("JWT_SECRET", "default_secret"),
AppURL: getEnv("APP_URL", "http://localhost:8080"),
GoogleClientID: getEnv("GOOGLE_CLIENT_ID", ""),
GoogleClientSecret: getEnv("GOOGLE_CLIENT_SECRET", ""),
GithubClientID: getEnv("GITHUB_CLIENT_ID", ""),
GithubClientSecret: getEnv("GITHUB_CLIENT_SECRET", ""),
ClientCallbackURL: getEnv("CLIENT_CALLBACK_URL", ""),
RedisUrl: getEnv("REDIS_URL", ""),
// Avatar Defaults
AvatarHeight: getEnvAsInt("AVATAR_H", 0), // Default 0 (auto)
AvatarWidth: getEnvAsInt("AVATAR_W", 800), // Default 800
AvatarQuality: getEnvAsInt("AVATAR_Q", 80), // Default 80
AvatarFormat: getEnv("AVATAR_F", "webp"), // Default webp
AvatarMode: getEnv("AVATAR_B", "contain"), // Default contain (Fit)
// Email Settings
EmailHost: getEnv("EMAIL_HOST", "localhost"),
EmailPort: getEnv("EMAIL_PORT", "1025"),
EmailHostUser: getEnv("EMAIL_HOST_USER", ""),
EmailHostPassword: getEnv("EMAIL_HOST_PASSWORD", ""),
EmailFrom: getEnv("EMAIL_FROM", "noreply@gauth.local"),
}
}
func getEnv(key, fallback string) string {
if value, exists := os.LookupEnv(key); exists {
return value
}
return fallback
}
func getEnvAsInt(key string, fallback int) int {
valueStr := getEnv(key, "")
if valueStr == "" {
return fallback
}
value, err := strconv.Atoi(valueStr)
if err != nil {
return fallback
}
return value
}