package config import ( "log" "github.com/kelseyhightower/envconfig" ) type appConfig struct { Port int `envconfig:"APP_PORT"` } type kafkaConfig struct { Port int `envconfig:"KAFKA_PORT"` Host string `envconfig:"KAFKA_HOST"` } // ... type Config struct { App appConfig Kafka kafkaConfig } func NewConfig() *Config { c := Config{} err := envconfig.Process("", &c) if err != nil { log.Fatal(err.Error()) } return &c }