From 0948ef9fa2808a4ef4288c4696b2e93648973172 Mon Sep 17 00:00:00 2001 From: James Tombleson Date: Fri, 26 Apr 2024 16:05:17 -0700 Subject: [PATCH] the config will now just return a struct from the env because this wa made to run in a container --- internal/services/config.go | 52 +++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/internal/services/config.go b/internal/services/config.go index d38ecc2..2099d44 100644 --- a/internal/services/config.go +++ b/internal/services/config.go @@ -32,6 +32,26 @@ const ( 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{} func NewConfig() ConfigClient { @@ -41,6 +61,38 @@ func NewConfig() ConfigClient { 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 { res, filled := os.LookupEnv(key) if !filled {