github.com/safedep/dry@v0.0.0-20241016050132-a15651f0548b/utils/env.go (about) 1 package utils 2 3 import ( 4 "os" 5 "strconv" 6 ) 7 8 // EnvBool looks up environment variable by name 9 // and converts the string value to bool. It returns 10 // default value if env does not exist or conversion 11 // to bool fails 12 func EnvBool(name string, def bool) bool { 13 val, ok := os.LookupEnv(name) 14 if !ok { 15 return def 16 } 17 18 bRet, err := strconv.ParseBool(val) 19 if err != nil { 20 return def 21 } 22 23 return bRet 24 }