package config import ( "os" "strconv" "time" ) type Config struct { DatabaseURL string FlareSolverrURL string FlareSolverrProxy bool Addr string MangaListTTL time.Duration MangaDetailTTL time.Duration ChapterListTTL time.Duration DBMaxConns int DBMinConns int } func Load() Config { return Config{ DatabaseURL: os.Getenv("DATABASE_URL"), FlareSolverrURL: os.Getenv("FLARESOLVERR_URL"), FlareSolverrProxy: envBool("FLARESOLVERR_PROXY", false), Addr: envStr("ADDR", ":8080"), MangaListTTL: time.Duration(envInt("MANGA_LIST_TTL_SECONDS", 600)) * time.Second, MangaDetailTTL: time.Duration(envInt("MANGA_DETAIL_TTL_SECONDS", 3600)) * time.Second, ChapterListTTL: time.Duration(envInt("CHAPTER_LIST_TTL_SECONDS", 600)) * time.Second, DBMaxConns: envInt("DB_MAX_CONNS", 10), DBMinConns: envInt("DB_MIN_CONNS", 2), } } func envStr(key, def string) string { if v := os.Getenv(key); v != "" { return v } return def } func envInt(key string, def int) int { if v := os.Getenv(key); v != "" { if n, err := strconv.Atoi(v); err == nil { return n } } return def } func envBool(key string, def bool) bool { if v := os.Getenv(key); v != "" { return v == "1" || v == "true" || v == "yes" } return def }