8058
Ir
irvc / files
irvc / config.go
1008 bytes
1package main 2 3import ( 4 "os" 5 "strconv" 6) 7 8type Config struct { 9 ListenAddr string 10 DBPath string 11 SessionSecret string 12 LiveKitURL string 13 LiveKitKey string 14 LiveKitSecret string 15 MediaDir string 16 MaxUpload int64 17 GiphyKey string 18} 19 20func LoadConfig() *Config { 21 return &Config{ 22 ListenAddr: env("IRVC_LISTEN_ADDR", ":8080"), 23 DBPath: env("IRVC_DB_PATH", "irvc.db"), 24 SessionSecret: env("IRVC_SESSION_SECRET", ""), 25 LiveKitURL: env("IRVC_LIVEKIT_URL", ""), 26 LiveKitKey: env("IRVC_LIVEKIT_API_KEY", ""), 27 LiveKitSecret: env("IRVC_LIVEKIT_SECRET", ""), 28 MediaDir: env("IRVC_MEDIA_DIR", "media"), 29 MaxUpload: envInt("IRVC_MAX_UPLOAD", 8<<20), 30 GiphyKey: os.Getenv("IRVC_GIPHY_API_KEY"), 31 } 32} 33 34func envInt(key string, def int64) int64 { 35 v, err := strconv.ParseInt(os.Getenv(key), 10, 64) 36 if err != nil || v <= 0 { 37 return def 38 } 39 return v 40} 41 42func env(key, def string) string { 43 if v := os.Getenv(key); v != "" { 44 return v 45 } 46 return def 47}