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 }