2
2
3
3
[ ![ Build Status] ( https://img.shields.io/github/actions/workflow/status/caarlos0/env/build.yml?branch=main&style=for-the-badge )] ( https://github.com/caarlos0/env/actions?workflow=build )
4
4
[ ![ Coverage Status] ( https://img.shields.io/codecov/c/gh/caarlos0/env.svg?logo=codecov&style=for-the-badge )] ( https://codecov.io/gh/caarlos0/env )
5
- [ ![ ] ( http://img.shields.io/badge/godoc-reference-5272B4.svg?style=for-the-badge )] ( https://pkg.go.dev/github.com/caarlos0/env/v9 )
5
+ [ ![ ] ( http://img.shields.io/badge/godoc-reference-5272B4.svg?style=for-the-badge )] ( https://pkg.go.dev/github.com/caarlos0/env/v10 )
6
6
7
7
A simple and zero-dependencies library to parse environment variables into
8
8
` struct ` s.
@@ -12,7 +12,7 @@ A simple and zero-dependencies library to parse environment variables into
12
12
Get the module with:
13
13
14
14
``` sh
15
- go get github.com/caarlos0/env/v9
15
+ go get github.com/caarlos0/env/v10
16
16
```
17
17
18
18
The usage looks like this:
@@ -24,16 +24,16 @@ import (
24
24
" fmt"
25
25
" time"
26
26
27
- " github.com/caarlos0/env/v9 "
27
+ " github.com/caarlos0/env/v10 "
28
28
)
29
29
30
30
type config struct {
31
31
Home string ` env:"HOME"`
32
32
Port int ` env:"PORT" envDefault:"3000"`
33
33
Password string ` env:"PASSWORD,unset"`
34
34
IsProduction bool ` env:"PRODUCTION"`
35
- Hosts []string ` env:"HOSTS" envSeparator:":"`
36
35
Duration time.Duration ` env:"DURATION"`
36
+ Hosts []string ` env:"HOSTS" envSeparator:":"`
37
37
TempFolder string ` env:"TEMP_FOLDER,expand" envDefault:"${HOME}/tmp"`
38
38
StringInts map [string ]int ` env:"MAP_STRING_INT"`
39
39
}
@@ -103,7 +103,7 @@ case of absence of it in the environment.
103
103
By default, slice types will split the environment value on ` , ` ; you can change
104
104
this behavior by setting the ` envSeparator ` tag. For map types, the default
105
105
separator between key and value is ` : ` and ` , ` for key-value pairs.
106
- The behavior can be changed by setting the ` envKeyValSeparator ` and
106
+ The behavior can be changed by setting the ` envKeyValSeparator ` and
107
107
` envSeparator ` tags accordingly.
108
108
109
109
## Custom Parser Funcs
@@ -119,7 +119,7 @@ field.
119
119
If you add a custom parser for, say ` Foo ` , it will also be used to parse
120
120
` *Foo ` and ` []Foo ` types.
121
121
122
- Check the examples in the [ go doc] ( http://pkg.go.dev/github.com/caarlos0/env/v9 )
122
+ Check the examples in the [ go doc] ( http://pkg.go.dev/github.com/caarlos0/env/v10 )
123
123
for more info.
124
124
125
125
### A note about ` TextUnmarshaler ` and ` time.Time `
@@ -181,10 +181,11 @@ type config struct {
181
181
```
182
182
183
183
This also works with ` envDefault ` :
184
+
184
185
``` go
185
186
import (
186
187
" fmt"
187
- " github.com/caarlos0/env/v9 "
188
+ " github.com/caarlos0/env/v10 "
188
189
)
189
190
190
191
type config struct {
@@ -249,13 +250,14 @@ package main
249
250
import (
250
251
" fmt"
251
252
" time"
252
- " github.com/caarlos0/env/v9"
253
+
254
+ " github.com/caarlos0/env/v10"
253
255
)
254
256
255
257
type config struct {
256
- Secret string ` env:"SECRET,file"`
257
- Password string ` env:"PASSWORD,file" envDefault:"/tmp/password"`
258
- Certificate string ` env:"CERTIFICATE,file,expand" envDefault:"${CERTIFICATE_FILE}"`
258
+ Secret string ` env:"SECRET,file"`
259
+ Password string ` env:"PASSWORD,file" envDefault:"/tmp/password"`
260
+ Certificate string ` env:"CERTIFICATE,file,expand" envDefault:"${CERTIFICATE_FILE}"`
259
261
}
260
262
261
263
func main () {
@@ -297,7 +299,7 @@ import (
297
299
" fmt"
298
300
" log"
299
301
300
- " github.com/caarlos0/env/v9 "
302
+ " github.com/caarlos0/env/v10 "
301
303
)
302
304
303
305
type Config struct {
@@ -337,7 +339,7 @@ import (
337
339
" fmt"
338
340
" log"
339
341
340
- " github.com/caarlos0/env/v9 "
342
+ " github.com/caarlos0/env/v10 "
341
343
)
342
344
343
345
type Config struct {
@@ -374,7 +376,7 @@ import (
374
376
" fmt"
375
377
" log"
376
378
377
- " github.com/caarlos0/env/v9 "
379
+ " github.com/caarlos0/env/v10 "
378
380
)
379
381
380
382
type Config struct {
@@ -408,7 +410,7 @@ import (
408
410
" fmt"
409
411
" log"
410
412
411
- " github.com/caarlos0/env/v9 "
413
+ " github.com/caarlos0/env/v10 "
412
414
)
413
415
414
416
type Config struct {
@@ -457,7 +459,7 @@ import (
457
459
" fmt"
458
460
" log"
459
461
460
- " github.com/caarlos0/env/v9 "
462
+ " github.com/caarlos0/env/v10 "
461
463
)
462
464
463
465
type Config struct {
@@ -497,7 +499,7 @@ import (
497
499
" fmt"
498
500
" log"
499
501
500
- " github.com/caarlos0/env/v9 "
502
+ " github.com/caarlos0/env/v10 "
501
503
)
502
504
503
505
type Config struct {
@@ -533,7 +535,7 @@ import (
533
535
" fmt"
534
536
" log"
535
537
536
- " github.com/caarlos0/env/v9 "
538
+ " github.com/caarlos0/env/v10 "
537
539
)
538
540
539
541
type Config struct {
@@ -542,7 +544,7 @@ type Config struct {
542
544
}
543
545
544
546
func main () {
545
- var cfg = Config{
547
+ cfg : = Config{
546
548
Username: " test" ,
547
549
Password: " 123456" ,
548
550
}
@@ -551,7 +553,7 @@ func main() {
551
553
fmt.Println (" failed:" , err)
552
554
}
553
555
554
- fmt.Printf (" %+v " , cfg) // {Username:admin Password:123456}
556
+ fmt.Printf (" %+v " , cfg) // {Username:admin Password:123456}
555
557
}
556
558
```
557
559
@@ -566,7 +568,7 @@ import (
566
568
" fmt"
567
569
" log"
568
570
569
- " github.com/caarlos0/env/v9 "
571
+ " github.com/caarlos0/env/v10 "
570
572
)
571
573
572
574
type Config struct {
@@ -594,7 +596,7 @@ func main() {
594
596
}
595
597
}
596
598
597
- fmt.Printf (" %+v " , cfg) // {Username:admin Password:123456}
599
+ fmt.Printf (" %+v " , cfg) // {Username:admin Password:123456}
598
600
}
599
601
```
600
602
0 commit comments