package main import ( "fmt" "github.com/kelseyhightower/envconfig" ) type Config struct { PgHost string `envconfig:"POSTGRES_HOSTNAME"` PgName string `envconfig:"POSTGRES_DB"` PgUser string `envconfig:"POSTGRES_USER"` PgPass string `envconfig:"POSTGRES_PASSWORD"` PgPort int `envconfig:"POSTGRES_PORT"` Listen string `envconfig:"LISTEN"` Secret string `envconfig:"SECRET"` } func (c *Config) DSN() string { return fmt.Sprintf( "host=%s user=%s password=%s dbname=%s port=%d sslmode=disable TimeZone=Europe/Moscow", c.PgHost, c.PgUser, c.PgPass, c.PgName, c.PgPort, ) } func GetConfig() (*Config, error) { c := new(Config) return c, envconfig.Process("", c) }