package config import ( "log" "github.com/kelseyhightower/envconfig" ) type dbConfig struct { Host string `envconfig:"DB_HOST"` Port int `envconfig:"DB_PORT"` } type appConfig struct { Port int `envconfig:"APP_PORT"` } type authConfig struct { SecretKey string `envconfig:"SECRET_KEY"` } type sentryConfig struct { DSN string `envconfig:"SENTRY_DSN"` } // ... type Config struct { Db dbConfig App appConfig Auth authConfig Sentry sentryConfig } func NewConfig() *Config { c := Config{} err := envconfig.Process("", &c) if err != nil { log.Fatal(err.Error()) } return &c }