Skip to content

Commit

Permalink
Add usage example to README
Browse files Browse the repository at this point in the history
  • Loading branch information
kelseyhightower committed Nov 8, 2013
1 parent f8eae96 commit 8c15243
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,55 @@
```Go
import "github.com/kelseyhightower/envconfig"
```

## Usage

Set some environment variables:

```Bash
export MYAPP_DEBUG=false
export MYAPP_PORT=8080
export MYAPP_USER=Kelsey
export MYAPP_RATE="0.5"
```

Write some code:

```Go
package main

import (
"fmt"
"log"

"github.com/kelseyhightower/envconfig"
)

type Specification struct {
Debug bool
Port int
User string
Rate float32
}

func main() {
var s Specification
err := envconfig.Process("myapp", &s)
if err != nil {
log.Fatal(err.Error())
}
_, err = fmt.Printf("Debug: %v\nPort: %d\nUser: %s\nRate: %f\n", s.Debug, s.Port, s.User, s.Rate)
if err != nil {
log.Fatal(err.Error())
}
}
```

Results:

```Bash
Debug: false
Port: 8080
User: Kelsey
Rate: 0.500000
```

0 comments on commit 8c15243

Please sign in to comment.