Chore: project init

This commit is contained in:
2026-02-24 13:18:43 +09:00
commit 3345549051
23 changed files with 788 additions and 0 deletions

48
pkg/config/config.go Normal file
View File

@@ -0,0 +1,48 @@
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
}