fixed bug

This commit is contained in:
Tordarus 2022-01-21 14:07:54 +01:00
parent e835dafe1a
commit fd8dc229ee

28
vars.go
View File

@ -25,7 +25,7 @@ func Rune(key string, defaultValue rune) rune {
func Int(key string, defaultValue int) int { func Int(key string, defaultValue int) int {
if v, ok := os.LookupEnv(key); ok { if v, ok := os.LookupEnv(key); ok {
if v2, err := strconv.ParseInt(v, 10, 64); err != nil { if v2, err := strconv.ParseInt(v, 10, 64); err == nil {
return int(v2) return int(v2)
} }
} }
@ -34,7 +34,7 @@ func Int(key string, defaultValue int) int {
func Int8(key string, defaultValue int8) int8 { func Int8(key string, defaultValue int8) int8 {
if v, ok := os.LookupEnv(key); ok { if v, ok := os.LookupEnv(key); ok {
if v2, err := strconv.ParseInt(v, 10, 64); err != nil { if v2, err := strconv.ParseInt(v, 10, 64); err == nil {
return int8(v2) return int8(v2)
} }
} }
@ -43,7 +43,7 @@ func Int8(key string, defaultValue int8) int8 {
func Int16(key string, defaultValue int16) int16 { func Int16(key string, defaultValue int16) int16 {
if v, ok := os.LookupEnv(key); ok { if v, ok := os.LookupEnv(key); ok {
if v2, err := strconv.ParseInt(v, 10, 64); err != nil { if v2, err := strconv.ParseInt(v, 10, 64); err == nil {
return int16(v2) return int16(v2)
} }
} }
@ -52,7 +52,7 @@ func Int16(key string, defaultValue int16) int16 {
func Int32(key string, defaultValue int32) int32 { func Int32(key string, defaultValue int32) int32 {
if v, ok := os.LookupEnv(key); ok { if v, ok := os.LookupEnv(key); ok {
if v2, err := strconv.ParseInt(v, 10, 64); err != nil { if v2, err := strconv.ParseInt(v, 10, 64); err == nil {
return int32(v2) return int32(v2)
} }
} }
@ -61,7 +61,7 @@ func Int32(key string, defaultValue int32) int32 {
func Int64(key string, defaultValue int64) int64 { func Int64(key string, defaultValue int64) int64 {
if v, ok := os.LookupEnv(key); ok { if v, ok := os.LookupEnv(key); ok {
if v2, err := strconv.ParseInt(v, 10, 64); err != nil { if v2, err := strconv.ParseInt(v, 10, 64); err == nil {
return v2 return v2
} }
} }
@ -70,7 +70,7 @@ func Int64(key string, defaultValue int64) int64 {
func Uint8(key string, defaultValue uint8) uint8 { func Uint8(key string, defaultValue uint8) uint8 {
if v, ok := os.LookupEnv(key); ok { if v, ok := os.LookupEnv(key); ok {
if v2, err := strconv.ParseUint(v, 10, 64); err != nil { if v2, err := strconv.ParseUint(v, 10, 64); err == nil {
return uint8(v2) return uint8(v2)
} }
} }
@ -79,7 +79,7 @@ func Uint8(key string, defaultValue uint8) uint8 {
func Uint16(key string, defaultValue uint16) uint16 { func Uint16(key string, defaultValue uint16) uint16 {
if v, ok := os.LookupEnv(key); ok { if v, ok := os.LookupEnv(key); ok {
if v2, err := strconv.ParseUint(v, 10, 64); err != nil { if v2, err := strconv.ParseUint(v, 10, 64); err == nil {
return uint16(v2) return uint16(v2)
} }
} }
@ -88,7 +88,7 @@ func Uint16(key string, defaultValue uint16) uint16 {
func Uint32(key string, defaultValue uint32) uint32 { func Uint32(key string, defaultValue uint32) uint32 {
if v, ok := os.LookupEnv(key); ok { if v, ok := os.LookupEnv(key); ok {
if v2, err := strconv.ParseUint(v, 10, 64); err != nil { if v2, err := strconv.ParseUint(v, 10, 64); err == nil {
return uint32(v2) return uint32(v2)
} }
} }
@ -97,7 +97,7 @@ func Uint32(key string, defaultValue uint32) uint32 {
func Uint64(key string, defaultValue uint64) uint64 { func Uint64(key string, defaultValue uint64) uint64 {
if v, ok := os.LookupEnv(key); ok { if v, ok := os.LookupEnv(key); ok {
if v2, err := strconv.ParseUint(v, 10, 64); err != nil { if v2, err := strconv.ParseUint(v, 10, 64); err == nil {
return v2 return v2
} }
} }
@ -106,7 +106,7 @@ func Uint64(key string, defaultValue uint64) uint64 {
func Float32(key string, defaultValue float32) float32 { func Float32(key string, defaultValue float32) float32 {
if v, ok := os.LookupEnv(key); ok { if v, ok := os.LookupEnv(key); ok {
if v2, err := strconv.ParseFloat(v, 64); err != nil { if v2, err := strconv.ParseFloat(v, 64); err == nil {
return float32(v2) return float32(v2)
} }
} }
@ -115,7 +115,7 @@ func Float32(key string, defaultValue float32) float32 {
func Float64(key string, defaultValue float64) float64 { func Float64(key string, defaultValue float64) float64 {
if v, ok := os.LookupEnv(key); ok { if v, ok := os.LookupEnv(key); ok {
if v2, err := strconv.ParseFloat(v, 64); err != nil { if v2, err := strconv.ParseFloat(v, 64); err == nil {
return v2 return v2
} }
} }
@ -124,7 +124,7 @@ func Float64(key string, defaultValue float64) float64 {
func Complex64(key string, defaultValue complex64) complex64 { func Complex64(key string, defaultValue complex64) complex64 {
if v, ok := os.LookupEnv(key); ok { if v, ok := os.LookupEnv(key); ok {
if v2, err := strconv.ParseComplex(v, 64); err != nil { if v2, err := strconv.ParseComplex(v, 64); err == nil {
return complex64(v2) return complex64(v2)
} }
} }
@ -133,7 +133,7 @@ func Complex64(key string, defaultValue complex64) complex64 {
func Complex128(key string, defaultValue complex128) complex128 { func Complex128(key string, defaultValue complex128) complex128 {
if v, ok := os.LookupEnv(key); ok { if v, ok := os.LookupEnv(key); ok {
if v2, err := strconv.ParseComplex(v, 64); err != nil { if v2, err := strconv.ParseComplex(v, 64); err == nil {
return v2 return v2
} }
} }
@ -142,7 +142,7 @@ func Complex128(key string, defaultValue complex128) complex128 {
func Bool(key string, defaultValue bool) bool { func Bool(key string, defaultValue bool) bool {
if v, ok := os.LookupEnv(key); ok { if v, ok := os.LookupEnv(key); ok {
if v2, err := strconv.ParseBool(v); err != nil { if v2, err := strconv.ParseBool(v); err == nil {
return v2 return v2
} }
} }