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 sentryConfig struct { DSN string `envconfig:"SENTRY_DSN"` } // ... type Config struct { Db dbConfig App appConfig Sentry sentryConfig } func NewConfig() *Config { c := Config{} err := envconfig.Process("", &c) if err != nil { log.Fatal(err.Error()) } return &c }