mirror of
https://github.com/watn3y/steamsalty.git
synced 2025-09-09 01:32:23 +02:00
feat: Parse environment variables from .env file
This commit is contained in:
parent
e654f8449c
commit
99a81a201b
3 changed files with 13 additions and 2 deletions
|
@ -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("")
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue