Skip to content

Commit 5b567c0

Browse files
committed
updated example
1 parent 4fe9a36 commit 5b567c0

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

README.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,16 @@
55

66
Implements a simple way of handling environment values. Each environment field is simply reflected by a
77
variable inside the Go program. Out of the box handlers for the types `bool`, `[]byte`, `time.Duration`,
8-
`int`, `[]int`, `string` and `[]string` are provided. Other types can be added by using
8+
`int`, `[]int`, `string`, `[]string` and `map[string]string` are provided. Other types can be added by using
99
the `RegisterField` function.
1010

1111
## Example
1212

1313
```go
1414
var (
15-
name = env.String("NAME", "joe")
16-
age = env.Int("AGE", 24)
15+
name = env.String("NAME", "joe")
16+
age = env.Int("AGE", 24)
17+
shifts = env.StringMap("SHIFTS", map[string]string{"monday": "9am - 5pm"})
1718
)
1819

1920
func main() {
@@ -28,6 +29,7 @@ If the program is called with `-print-env`, all registered environment fields wo
2829
```bash
2930
NAME="joe"
3031
AGE="24"
32+
SHIFTS="monday:\"9am - 5pm\""
3133
```
3234

3335
By using `-print-env -print-env-format long-bash`, a description for each field is generated.
@@ -38,6 +40,9 @@ NAME="joe"
3840

3941
# Int field. The default value is '24'. Defined at .../main.go:10.
4042
AGE="24"
43+
44+
# StringMap fields. The default value is 'monday:\"9am - 5pm\"'. Defined at .../main.go:9.
45+
SHIFTS="monday:\"9am - 5pm\""
4146
```
4247

4348
## License

example/simple/main.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@ import (
77
)
88

99
var (
10-
name = env.String("NAME", "joe")
11-
age = env.Int("AGE", 24)
10+
name = env.String("NAME", "joe")
11+
age = env.Int("AGE", 24)
12+
shifts = env.StringMap("SHIFTS", map[string]string{"monday": "9am - 5pm"})
1213
)
1314

1415
func main() {
1516
env.ParseFlags()
1617

17-
fmt.Printf("%s is %d years old\n", name.Get(), age.Get())
18+
fmt.Printf("%s is %d years old\nshifts are %v\n",
19+
name.GetOrDefault(), age.GetOrDefault(), shifts.GetOrDefault())
1820
}

0 commit comments

Comments
 (0)