22[ ![ Go Reference] ( https://pkg.go.dev/badge/github.com/obalunenko/getenv.svg )] ( https://pkg.go.dev/github.com/obalunenko/getenv )
33[ ![ Go Report Card] ( https://goreportcard.com/badge/github.com/obalunenko/getenv )] ( https://goreportcard.com/report/github.com/obalunenko/getenv )
44[ ![ codecov] ( https://codecov.io/gh/obalunenko/getenv/branch/master/graph/badge.svg )] ( https://codecov.io/gh/obalunenko/getenv )
5- ![ coverbadger-tag-do-not-edit] ( https://img.shields.io/badge/coverage-98.93 %25-brightgreen?longCache=true&style=flat )
5+ ![ coverbadger-tag-do-not-edit] ( https://img.shields.io/badge/coverage-100 %25-brightgreen?longCache=true&style=flat )
66[ ![ Quality Gate Status] ( https://sonarcloud.io/api/project_badges/measure?project=obalunenko_getenv&metric=alert_status )] ( https://sonarcloud.io/summary/new_code?id=obalunenko_getenv )
77
88# getenv
@@ -30,6 +30,8 @@ Types supported:
3030- [ ] uint64
3131- uint
3232- [ ] uint
33+ - uintptr
34+ - [ ] uintptr
3335- uint32
3436- [ ] uint32
3537- float32
@@ -41,18 +43,23 @@ Types supported:
4143- time.Duration
4244- [ ] time.Duration
4345- bool
46+ - [ ] bool
4447- url.URL
4548- [ ] url.URL
4649- net.IP
4750- [ ] net.IP
51+ - complex64
52+ - [ ] complex64
53+ - complex128
54+ - [ ] complex128
4855
4956## Examples
5057
5158### EnvOrDefault
5259
53- EnvOrDefault retrieves the value of the environment variable named
54- by the key .
55- If variable not set or value is empty - defaultVal will be returned.
60+ EnvOrDefault retrieves the value of the environment variable named by the key.
61+ If the variable is present in the environment the value will be parsed and returned .
62+ Otherwise, the default value will be returned.
5663
5764``` golang
5865package main
@@ -140,6 +147,30 @@ func main() {
140147 val = getenv.EnvOrDefault (key, net.IP {})
141148 fmt.Printf (" [%T ]: %v \n " , val, val)
142149
150+ // []string
151+ if err := os.Setenv (key, " a,b,c,d" ); err != nil {
152+ panic (err)
153+ }
154+
155+ val = getenv.EnvOrDefault (key, []string {}, option.WithSeparator (" ," ))
156+ fmt.Printf (" [%T ]: %v \n " , val, val)
157+
158+ // complex128
159+ if err := os.Setenv (key, " 1+2i" ); err != nil {
160+ panic (err)
161+ }
162+
163+ val = getenv.EnvOrDefault (key, complex128 (0 ))
164+ fmt.Printf (" [%T ]: %v \n " , val, val)
165+
166+ // []complex64
167+ if err := os.Setenv (key, " 1+2i,3+4i" ); err != nil {
168+ panic (err)
169+ }
170+
171+ val = getenv.EnvOrDefault (key, []complex64 {}, option.WithSeparator (" ," ))
172+ fmt.Printf (" [%T ]: %v \n " , val, val)
173+
143174}
144175
145176```
@@ -154,4 +185,7 @@ Output:
154185[time.Duration]: 2h35m0s
155186[url.URL]: {https test:abcd123 golangbyexample.com:8000 /tutorials/intro false false type=advance&compact=false history }
156187[net.IP]: 2001:cb8::17
188+ [[]string]: [a b c d]
189+ [complex128]: (1+2i)
190+ [[]complex64]: [(1+2i) (3+4i)]
157191```
0 commit comments