mirror-nourybot/internal/config/config.go

49 lines
719 B
Go
Raw Normal View History

2022-03-06 20:19:55 +01:00
package config
import (
"os"
"github.com/joho/godotenv"
log "github.com/sirupsen/logrus"
)
type Config struct {
2022-03-07 16:45:16 +01:00
// Bot
2022-03-06 20:19:55 +01:00
Username string
BotUserId string
2022-03-07 16:45:16 +01:00
Oauth string
// Admin
AdminUsername string
AdminUserId string
// DB
MongoURI string
2022-03-06 20:19:55 +01:00
}
func LoadConfig() *Config {
err := godotenv.Load()
if err != nil {
log.Fatal("Error loading .env")
}
cfg := &Config{
2022-03-07 16:45:16 +01:00
// Bot
2022-03-06 20:40:00 +01:00
Username: os.Getenv("BOT_USERNAME"),
Oauth: os.Getenv("BOT_PASS"),
2022-03-06 20:19:55 +01:00
BotUserId: os.Getenv("BOT_USER_ID"),
2022-03-07 16:45:16 +01:00
// Admin
AdminUsername: os.Getenv("ADMIN_USER_NAME"),
AdminUserId: os.Getenv("ADMIN_USER_ID"),
// DB
MongoURI: os.Getenv("MONGO_URI"),
2022-03-06 20:19:55 +01:00
}
log.Info("Config loaded succesfully")
return cfg
}