• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

.travis.ymlH A D28-Aug-2018154

LICENSEH A D28-Aug-20181.1 KiB

README.mdH A D28-Aug-2018819

doc.goH A D28-Aug-2018220

env.goH A D28-Aug-20183.3 KiB

env_test.goH A D28-Aug-20189.6 KiB

example_test.goH A D28-Aug-2018338

README.md

1# What is it?
2
3[![Build Status](https://travis-ci.org/olivere/env.svg?branch=master)](https://travis-ci.org/olivere/env)
4
5The `env` package is to simplify reading environment variables with e.g.
6the `flag` package.
7
8Example:
9
10In our `main`, we often allow users to initialize our programs via flags.
11When users leave out the flags, we want to fall back to environment variables.
12The `env` package simplifies this scenario.
13
14```go
15import (
16    "flag"
17    "fmt"
18)
19
20func main() {
21	var (
22		// Parse addr from flag, use HTTP_ADDR and ADDR env vars as fallback
23		addr = flag.String("addr", env.String("127.0.0.1:3000", "HTTP_ADDR", "ADDR"), "Bind to this address")
24	)
25	flag.Parse()
26
27	fmt.Println(*addr)
28	// Output: 127.0.0.1:3000
29}
30```
31
32# License
33
34MIT. See [LICENSE](https://github.com/olivere/env/blob/master/LICENSE) file.
35