2022-04-29 13:02:25 -07:00
|
|
|
package config
|
2022-04-02 12:05:32 -07:00
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"log"
|
2022-04-17 07:25:49 -07:00
|
|
|
|
2022-04-02 12:05:32 -07:00
|
|
|
"github.com/joho/godotenv"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
DB_URI string = "DB_URI"
|
|
|
|
|
|
|
|
REDDIT_PULL_TOP = "REDDIT_PULL_TOP"
|
|
|
|
REDDIT_PULL_HOT = "REDDIT_PULL_HOT"
|
|
|
|
REDDIT_PULL_NSFW = "REDDIT_PULL_NSFW"
|
2022-04-17 07:25:49 -07:00
|
|
|
|
|
|
|
YOUTUBE_DEBUG = "YOUTUBE_DEBUG"
|
2022-05-15 21:48:23 -07:00
|
|
|
|
|
|
|
TWITCH_CLIENT_ID = "TWITCH_CLIENT_ID"
|
|
|
|
TWITCH_CLIENT_SECRET = "TWITCH_CLIENT_SECRET"
|
|
|
|
TWITCH_MONITOR_CLIPS = "TWITCH_MONITOR_CLIPS"
|
|
|
|
TWITCH_MONITOR_VOD = "TWITCH_MONITOR_VOD"
|
2022-04-02 12:05:32 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
type ConfigClient struct {}
|
|
|
|
|
2022-04-29 13:02:25 -07:00
|
|
|
func New() ConfigClient {
|
2022-04-02 12:05:32 -07:00
|
|
|
_, err := os.Open(".env")
|
|
|
|
if err == nil {
|
|
|
|
loadEnvFile()
|
|
|
|
}
|
|
|
|
|
|
|
|
return ConfigClient{}
|
|
|
|
}
|
|
|
|
|
2022-04-17 07:25:49 -07:00
|
|
|
func (cc *ConfigClient) GetConfig(key string) string {
|
2022-04-02 12:05:32 -07:00
|
|
|
res, filled := os.LookupEnv(key)
|
|
|
|
if !filled {
|
|
|
|
log.Printf("Missing the a value for '%v'. Could generate errors.", key)
|
|
|
|
}
|
|
|
|
return res
|
|
|
|
}
|
|
|
|
|
|
|
|
// Use this when your ConfigClient has been opened for awhile and you want to ensure you have the most recent env changes.
|
2022-04-17 07:25:49 -07:00
|
|
|
func (cc *ConfigClient) RefreshEnv() {
|
2022-04-02 12:05:32 -07:00
|
|
|
loadEnvFile()
|
|
|
|
}
|
|
|
|
|
|
|
|
func loadEnvFile() {
|
|
|
|
err := godotenv.Load()
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalln(err)
|
|
|
|
}
|
|
|
|
}
|