Skip to content

Commit

Permalink
Merge pull request #25 from segmentio/env-var-readme
Browse files Browse the repository at this point in the history
Clarify env variable usage
  • Loading branch information
tysonmote committed Jul 3, 2018
2 parents ea2d218 + 3f0e70f commit cee1e55
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,32 @@ $ go run ./example.go -m 'Hello World!'
Hello World!
```

Environment Variables
---------------------

By default, `conf` will look for environment variables before loading command-line configuration flags with one important caveat: environment variables are prefixed with the program name. For example, given a program named "foobar":

```
func main() {
config := struct {
Name string `conf:"name"`
}{
Name: "default",
}
conf.Load(&config)
fmt.Println("Hello", config.Name)
}
```

The following will be output:

```
$ ./foobar // "Hello default"
$ FOOBAR_NAME=world ./foobar // "Hello world"
$ FOOBAR_NAME=world ./foobar --name neighbor // "Hello neighbor"
$ MAIN_NAME=world go run main.go // "Hello world"
```

Advanced Usage
--------------

Expand Down

0 comments on commit cee1e55

Please sign in to comment.