Files
affiliate_dash/backend/internal/config/config.go
T
2026-07-20 14:58:57 +08:00

39 lines
662 B
Go

package config
import (
"os"
"strconv"
)
type Config struct {
Port string
JWTSecret string
DBPath string
Mode string // debug / release
}
func Load() *Config {
return &Config{
Port: getEnv("PORT", "8080"),
JWTSecret: getEnv("JWT_SECRET", "affiliate-dash-dev-secret-change-me"),
DBPath: getEnv("DB_PATH", "data/app.db"),
Mode: getEnv("GIN_MODE", "debug"),
}
}
func getEnv(key, def string) string {
if v := os.Getenv(key); v != "" {
return v
}
return def
}
func getEnvInt(key string, def int) int {
if v := os.Getenv(key); v != "" {
if n, err := strconv.Atoi(v); err == nil {
return n
}
}
return def
}