mirror of
https://github.com/watn3y/steamsalty.git
synced 2025-09-08 01:02:24 +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("")
|
||||
|
||||
}
|
||||
|
|
1
go.mod
1
go.mod
|
@ -12,6 +12,7 @@ require (
|
|||
|
||||
require (
|
||||
github.com/andybalholm/cascadia v1.3.3 // indirect
|
||||
github.com/joho/godotenv v1.5.1 // indirect
|
||||
github.com/mattn/go-colorable v0.1.14 // indirect
|
||||
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||
golang.org/x/net v0.43.0 // indirect
|
||||
|
|
2
go.sum
2
go.sum
|
@ -10,6 +10,8 @@ github.com/go-telegram-bot-api/telegram-bot-api/v5 v5.5.1/go.mod h1:A2S0CWkNylc2
|
|||
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
|
||||
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
|
||||
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
||||
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
|
||||
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
|
||||
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
|
||||
github.com/mattn/go-colorable v0.1.14 h1:9A9LHSqF/7dyVVX6g0U9cwm9pG3kP9gSzcuIPHPsaIE=
|
||||
github.com/mattn/go-colorable v0.1.14/go.mod h1:6LmQG8QLFO4G5z1gPvYEzlUgJ2wF+stgPZH1UqBm1s8=
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue