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
- Host: GitHub
- URL: https://github.com/matansh/enver
- Owner: matansh
- License: unlicense
- Created: 2022-08-11T09:52:13.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2023-01-25T13:34:02.000Z (over 3 years ago)
- Last Synced: 2026-01-14T14:03:37.046Z (5 months ago)
- Topics: 12-factor, 12factor, 12factorapp, config, configuration, env, environment, environment-variables, freeware, go, golang, struct
- Language: Go
- Homepage:
- Size: 8.79 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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 ;)