/envconfig

Organize configs in a clean way.

Primary LanguageGo

EnvConfig

Organize configs in a clean way.

TODO

  • Support parsing configs from remote key value store, such as ZooKeeper or Redis

Getting Started

  1. Install the library.

    go get github.com/short-d/envconfig
  2. Parse configs from environmental variables.

    import "github.com/short-d/envconfig"
    
    envConfig := envconfig.NewDefault()
    
    config := struct {
        DBHost     string `env:"DB_HOST" default:"localhost"`
        DBPort     int    `env:"DB_PORT" default:"5432"`
        DBUser     string `env:"DB_USER" default:"postgres"`
        DBPassword string `env:"DB_PASSWORD" default:"password"`
        DBName     string `env:"DB_NAME" default:"sampleapp"`
    }{}
    err := envConfig.ParseConfigFromEnv(&config)
    if err != nil {
        panic(err)
    }

License

This project is maintained under MIT license.