Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/simia-tech/env
Golang handling of environment values
https://github.com/simia-tech/env
Last synced: 6 days ago
JSON representation
Golang handling of environment values
- Host: GitHub
- URL: https://github.com/simia-tech/env
- Owner: simia-tech
- License: apache-2.0
- Created: 2018-01-15T09:17:55.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2023-08-31T09:36:34.000Z (about 1 year ago)
- Last Synced: 2024-06-21T03:20:46.599Z (5 months ago)
- Language: Go
- Size: 91.8 KB
- Stars: 1
- Watchers: 4
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# env
[![GoDoc](https://godoc.org/github.com/simia-tech/env?status.svg)](https://godoc.org/github.com/simia-tech/env) [![Build Status](https://travis-ci.org/simia-tech/env.svg?branch=master)](https://travis-ci.org/simia-tech/env)
Implements a simple way of handling environment values. Each environment field is simply reflected by a
variable inside the Go program. Out of the box handlers for the types `bool`, `[]byte`, `time.Duration`,
`int`, `[]int`, `string`, `[]string` and `map[string]string` are provided. Other types can be added by using
the `RegisterField` function.## Example
```go
package mainimport (
"fmt""github.com/simia-tech/env/v2"
)var (
name = env.String("NAME", "joe")
age = env.Int("AGE", 24)
shifts = env.StringMap("SHIFTS", map[string]string{"monday": "9am - 5pm"})
)func main() {
env.ParseFlags()fmt.Printf("%s is %d years old\nshifts are %v\n",
name.GetOrDefault(), age.GetOrDefault(), shifts.GetOrDefault())
}
```If the program is called with `-print-env`, all registered environment fields would be printed...
```bash
NAME="joe"
AGE="24"
SHIFTS="monday:\"9am - 5pm\""
```By using `-print-env -print-env-format long-bash`, a description for each field is generated.
```bash
# String field. The default value is 'joe'. Defined at .../main.go:11.
NAME="joe"# Int field. The default value is '24'. Defined at .../main.go:10.
AGE="24"# StringMap fields. The default value is 'monday:\"9am - 5pm\"'. Defined at .../main.go:9.
SHIFTS="monday:\"9am - 5pm\""
```## License
The project is licensed under [Apache 2.0](http://www.apache.org/licenses/LICENSE-2.0).