the config will now just return a struct from the env because this wa made to run in a container

This commit is contained in:
James Tombleson 2024-04-26 16:05:17 -07:00
parent d35b955815
commit 0948ef9fa2

View File

@ -32,6 +32,26 @@ const (
FEATURE_ENABLE_FFXIV_BACKEND = "FEATURE_ENABLE_FFXIV_BACKEND" FEATURE_ENABLE_FFXIV_BACKEND = "FEATURE_ENABLE_FFXIV_BACKEND"
) )
type Configs struct {
ServerAddress string
RedditEnabled bool
RedditPullTop bool
RedditPullHot bool
RedditPullNsfw bool
YoutubeEnabled bool
YoutubeDebug bool
TwitchEnabled bool
TwitchClientId string
TwitchClientSecret string
TwitchMonitorClips bool
TwitchMonitorVOD bool
FfxivEnabled bool
}
type ConfigClient struct{} type ConfigClient struct{}
func NewConfig() ConfigClient { func NewConfig() ConfigClient {
@ -41,6 +61,38 @@ func NewConfig() ConfigClient {
return c return c
} }
func GetEnvConfig() Configs {
return Configs{
ServerAddress: os.Getenv(ServerAddress),
RedditEnabled: processBoolConfig(os.Getenv(FEATURE_ENABLE_REDDIT_BACKEND)),
RedditPullTop: processBoolConfig(os.Getenv(REDDIT_PULL_TOP)),
RedditPullHot: processBoolConfig(os.Getenv(REDDIT_PULL_HOT)),
RedditPullNsfw: processBoolConfig(os.Getenv(REDDIT_PULL_NSFW)),
YoutubeEnabled: processBoolConfig(os.Getenv(FEATURE_ENABLE_YOUTUBE_BACKEND)),
YoutubeDebug: processBoolConfig(os.Getenv(YOUTUBE_DEBUG)),
TwitchEnabled: processBoolConfig(os.Getenv(FEATURE_ENABLE_TWITCH_BACKEND)),
TwitchClientId: os.Getenv(TWITCH_CLIENT_ID),
TwitchClientSecret: os.Getenv(TWITCH_CLIENT_SECRET),
TwitchMonitorClips: processBoolConfig(TWITCH_MONITOR_CLIPS),
TwitchMonitorVOD: processBoolConfig(os.Getenv(TWITCH_MONITOR_VOD)),
FfxivEnabled: processBoolConfig(os.Getenv(FEATURE_ENABLE_FFXIV_BACKEND)),
}
}
// This will parse a string and convert it to a bool.
// If it runs into any errors, it will default to false
func processBoolConfig(value string) bool {
b, err := strconv.ParseBool(value)
if err != nil {
return false
}
return b
}
func (cc *ConfigClient) GetConfig(key string) string { func (cc *ConfigClient) GetConfig(key string) string {
res, filled := os.LookupEnv(key) res, filled := os.LookupEnv(key)
if !filled { if !filled {