https://github.com/joegasewicz/env-conf
Grabs environmental variables & maps them to your config type via struct tags
https://github.com/joegasewicz/env-conf
Last synced: 6 months ago
JSON representation
Grabs environmental variables & maps them to your config type via struct tags
- Host: GitHub
- URL: https://github.com/joegasewicz/env-conf
- Owner: joegasewicz
- License: mit
- Created: 2022-11-04T15:59:15.000Z (almost 3 years ago)
- Default Branch: master
- Last Pushed: 2022-11-05T12:16:54.000Z (almost 3 years ago)
- Last Synced: 2025-04-10T13:34:12.560Z (6 months ago)
- Language: Go
- Homepage: https://pkg.go.dev/github.com/joegasewicz/env-conf
- Size: 10.7 KB
- Stars: 5
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ENV Conf
Grabs environmental variables & maps them to your config type via struct tags```
go get -u github.com/joegasewicz/env-conf
```### Usage
If an environment variable returns an empty string then the default config
struct member will not be overridden.
```go
os.Setenv("ENV_ONE", "apples")
os.Setenv("ENV_TWO", "bananas")type Config struct {
EnvOne string `env_conf:"ENV_ONE"`
EnvTwo string `env_conf:"ENV_TWO"`
}c := Config{}
err := env_conf.Update(&c)fmt.Println("ENV_ONE: ", c.EnvOne) // apples
```#### Set Defaults
Using a `:` colon to set defaults,
the environment variable is on the left side & the default is on the right side.
```go
type Config struct {
EnvOne string `env_conf:"ENV_ONE:http://127.0.0.1:8080"`
}
// If `ENV_ONE` does not exist then `EnvOne` will equal http://127.0.0.1:8080
```