38 lines
1.1 KiB
Go
38 lines
1.1 KiB
Go
package config
|
|
|
|
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"`
|
|
WebhookURL string `default:"" env:"WEBHOOK_URL" yaml:"webhook_url" toml:"webhook_url"`
|
|
Listen string `default:"" env:"LISTEN" yaml:"listen" toml:"listen"`
|
|
Debug bool `default:"false" env:"DEBUG" yaml:"debug" toml:"debug"`
|
|
}
|
|
|
|
func LoadConfig() (*Config, error) {
|
|
var cfg Config
|
|
_ = godotenv.Load()
|
|
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
|
|
}
|