50 lines
978 B
Go
50 lines
978 B
Go
package config
|
|
|
|
import (
|
|
"nearle/utils"
|
|
"os"
|
|
)
|
|
|
|
type Config struct {
|
|
Env string
|
|
Port string
|
|
DBName string
|
|
DBUser string
|
|
DBPassword string
|
|
DBPort string
|
|
DBHost string
|
|
UserContextKey string
|
|
JWTSecret string
|
|
}
|
|
|
|
func Load() *Config {
|
|
cfg := &Config{
|
|
Env: getEnv("ENV", "production"),
|
|
Port: getEnv("APP_PORT", "1009"),
|
|
|
|
// ✅ STANDARDIZED DB ENV KEYS
|
|
DBName: getEnv("DB_NAME", ""),
|
|
DBUser: getEnv("DB_USER", ""),
|
|
DBPassword: getEnv("DB_PASSWORD", ""),
|
|
DBPort: getEnv("DB_PORT", "5432"),
|
|
DBHost: getEnv("DB_HOST", "localhost"),
|
|
|
|
UserContextKey: getEnv("USER_CONTEXT_KEY", "nearle"),
|
|
JWTSecret: getEnv("JWT_SECRET_KEY", ""),
|
|
}
|
|
|
|
// ✅ Correct validation
|
|
if cfg.DBPassword == "" {
|
|
utils.Logger.Warn("Warning: DB_PASSWORD is not set")
|
|
}
|
|
|
|
return cfg
|
|
}
|
|
|
|
func getEnv(key, fallback string) string {
|
|
if v := os.Getenv(key); v != "" {
|
|
return v
|
|
}
|
|
return fallback
|
|
}
|