38 lines
1010 B
Go
38 lines
1010 B
Go
|
package app
|
||
|
|
||
|
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"`
|
||
|
Debug bool `default:"false" env:"DEBUG" yaml:"debug" toml:"debug"`
|
||
|
}
|
||
|
|
||
|
func LoadConfig() (*Config, error) {
|
||
|
var cfg Config
|
||
|
if err := godotenv.Load(); err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
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
|
||
|
}
|