2021-10-13 21:30:31 +02:00
|
|
|
package config
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
|
|
|
|
"github.com/joho/godotenv"
|
|
|
|
log "github.com/sirupsen/logrus"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Config struct {
|
2021-11-07 17:33:39 +01:00
|
|
|
Username string
|
|
|
|
Oauth string
|
|
|
|
BotUserId string
|
|
|
|
MongoURI string
|
2021-10-13 21:30:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func LoadConfig() *Config {
|
|
|
|
err := godotenv.Load()
|
2021-10-21 00:07:18 +02:00
|
|
|
|
2021-10-13 21:30:31 +02:00
|
|
|
if err != nil {
|
|
|
|
log.Fatal("Error loading .env")
|
|
|
|
}
|
|
|
|
|
|
|
|
cfg := &Config{
|
2021-11-07 17:33:39 +01:00
|
|
|
Username: os.Getenv("TWITCH_USER"),
|
|
|
|
Oauth: os.Getenv("TWITCH_PASS"),
|
|
|
|
BotUserId: os.Getenv("BOT_USER_ID"),
|
|
|
|
MongoURI: os.Getenv("MONGO_URI"),
|
2021-10-13 21:30:31 +02:00
|
|
|
}
|
2021-10-21 00:07:18 +02:00
|
|
|
|
2021-10-13 21:30:31 +02:00
|
|
|
log.Info("Config loaded succesfully")
|
|
|
|
|
|
|
|
return cfg
|
|
|
|
}
|
2021-10-28 23:31:59 +02:00
|
|
|
|
|
|
|
// Only for tests
|
|
|
|
func LoadConfigTest() {
|
|
|
|
os.Setenv("TEST_VALUE", "xDLUL420")
|
|
|
|
// defer os.Unsetenv("TEST_VALUE")
|
|
|
|
}
|