Files
a301_server/pkg/config/config.go
2026-02-24 13:18:43 +09:00

49 lines
1022 B
Go

package config
import (
"os"
"strconv"
"github.com/joho/godotenv"
)
type Config struct {
AppPort string
DBHost string
DBPort string
DBUser string
DBPassword string
DBName string
RedisAddr string
RedisPassword string
JWTSecret string
JWTExpiryHours int
}
var C Config
func Load() {
_ = godotenv.Load()
hours, _ := strconv.Atoi(getEnv("JWT_EXPIRY_HOURS", "24"))
C = Config{
AppPort: getEnv("APP_PORT", "8080"),
DBHost: getEnv("DB_HOST", "localhost"),
DBPort: getEnv("DB_PORT", "3306"),
DBUser: getEnv("DB_USER", "root"),
DBPassword: getEnv("DB_PASSWORD", ""),
DBName: getEnv("DB_NAME", "a301"),
RedisAddr: getEnv("REDIS_ADDR", "localhost:6379"),
RedisPassword: getEnv("REDIS_PASSWORD", ""),
JWTSecret: getEnv("JWT_SECRET", "secret"),
JWTExpiryHours: hours,
}
}
func getEnv(key, fallback string) string {
if v := os.Getenv(key); v != "" {
return v
}
return fallback
}