vegapokerbot/internal/config/config.go

38 lines
1.1 KiB
Go
Raw Permalink Normal View History

2024-05-07 22:07:53 +03:00
package config
2024-05-07 21:49:09 +03:00
import (
"github.com/cristalhq/aconfig"
"github.com/cristalhq/aconfig/aconfigtoml"
"github.com/cristalhq/aconfig/aconfigyaml"
"github.com/joho/godotenv"
"os"
)
type Config struct {
PostgresDSN string `default:"" env:"POSTGRES_DSN" yaml:"postgres_dsn" toml:"postgres_dsn"`
TelegramToken string `default:"" env:"TELEGRAM_TOKEN" yaml:"telegram_token" toml:"telegram_token"`
2024-05-10 11:46:43 +03:00
WebhookURL string `default:"" env:"WEBHOOK_URL" yaml:"webhook_url" toml:"webhook_url"`
Listen string `default:"" env:"LISTEN" yaml:"listen" toml:"listen"`
2024-05-07 21:49:09 +03:00
Debug bool `default:"false" env:"DEBUG" yaml:"debug" toml:"debug"`
}
func LoadConfig() (*Config, error) {
var cfg Config
2024-05-10 12:10:25 +03:00
_ = godotenv.Load()
2024-05-07 21:49:09 +03:00
loader := aconfig.LoaderFor(&cfg, aconfig.Config{
SkipFlags: true,
EnvPrefix: "POKER_BOT",
Envs: os.Environ(),
Files: []string{"config.json", "config.yaml", "config.yml"},
FileDecoders: map[string]aconfig.FileDecoder{
".yaml": aconfigyaml.New(),
".yml": aconfigyaml.New(),
".toml": aconfigtoml.New(),
},
})
if err := loader.Load(); err != nil {
return nil, err
}
return &cfg, nil
}