nquest/config.go

35 lines
657 B
Go
Raw Normal View History

2023-11-01 23:21:12 +03:00
package main
import (
"fmt"
"github.com/kelseyhightower/envconfig"
)
type Config struct {
PgHost string `envconfig:"PG_HOST"`
PgName string `envconfig:"PG_NAME"`
PgUser string `envconfig:"PG_USER"`
PgPass string `envconfig:"PG_PASS"`
PgPort int `envconfig:"PG_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)
}