An open API service indexing awesome lists of open source software.

https://github.com/matansh/enver

Populate a golang struct with env var values
https://github.com/matansh/enver

12-factor 12factor 12factorapp config configuration env environment environment-variables freeware go golang struct

Last synced: 3 months ago
JSON representation

Populate a golang struct with env var values

Awesome Lists containing this project

README

          

# enver
A Go(lang) configuration library.

## Usage
```go
import "github.com/matansh/enver/config"

type Config struct {
LogLevel string `env:"LOG_LEVEL"`
Port int64 `env:"PORT"`
FeatureFlag bool `env:"TURN_ON_FEATURE"`
ExplicitlyIgnored string `env:"-"` // passing "-" instructs the lib not to populate this field
ImplicitlyIgnored string // untagged struct fields will be ignored
}

func main() {
var cfg Config

errs := config.LoadEnv(&cfg)
if len(errs) != 0 {
// failed to load config
}
}
```

## Background
This library is intended to help projects implement the twelve-factor app methodology - https://12factor.net/

### footnote
This library is intentionally dependency-less in order to minimize the dependency trees of its importers, you are welcome ;)