feat: Parse environment variables from .env file

This commit is contained in:
Noah 2025-08-31 03:49:57 +02:00
parent e654f8449c
commit 99a81a201b
No known key found for this signature in database
GPG key ID: D2A7E2C8F77E0430
3 changed files with 13 additions and 2 deletions

View file

@ -5,18 +5,26 @@ import (
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
"github.com/joho/godotenv"
envconfig "github.com/sethvargo/go-envconfig"
)
var BotConfig config
func LoadConfig() {
if err := godotenv.Load(); err != nil {
log.Info().Err(err).Msg("Failed to load .env file, using the system environment")
} else {
log.Info().Err(err).Msg(".env file loaded successfully")
}
if err := envconfig.Process(context.Background(), &BotConfig); err != nil {
log.Panic().Err(err).Msg("Error parsing config from env variables")
log.Panic().Err(err).Msg("Failed to parse config from env variables")
}
zerolog.SetGlobalLevel(zerolog.Level(BotConfig.LogLevel))
log.Info().Msg("Loaded config")
log.Info().Msg("Config loaded successfully")
log.Debug().Interface("config", BotConfig).Msg("")
}