From fd8dc229ee8f012f7178724441eac26c1eff25af Mon Sep 17 00:00:00 2001 From: Tordarus Date: Fri, 21 Jan 2022 14:07:54 +0100 Subject: [PATCH] fixed bug --- vars.go | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/vars.go b/vars.go index 658dfdd..0799ce9 100644 --- a/vars.go +++ b/vars.go @@ -25,7 +25,7 @@ func Rune(key string, defaultValue rune) rune { func Int(key string, defaultValue int) int { 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) } } @@ -34,7 +34,7 @@ func Int(key string, defaultValue int) int { func Int8(key string, defaultValue int8) int8 { 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) } } @@ -43,7 +43,7 @@ func Int8(key string, defaultValue int8) int8 { func Int16(key string, defaultValue int16) int16 { 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) } } @@ -52,7 +52,7 @@ func Int16(key string, defaultValue int16) int16 { func Int32(key string, defaultValue int32) int32 { 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) } } @@ -61,7 +61,7 @@ func Int32(key string, defaultValue int32) int32 { func Int64(key string, defaultValue int64) int64 { 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 } } @@ -70,7 +70,7 @@ func Int64(key string, defaultValue int64) int64 { func Uint8(key string, defaultValue uint8) uint8 { 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) } } @@ -79,7 +79,7 @@ func Uint8(key string, defaultValue uint8) uint8 { func Uint16(key string, defaultValue uint16) uint16 { 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) } } @@ -88,7 +88,7 @@ func Uint16(key string, defaultValue uint16) uint16 { func Uint32(key string, defaultValue uint32) uint32 { 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) } } @@ -97,7 +97,7 @@ func Uint32(key string, defaultValue uint32) uint32 { func Uint64(key string, defaultValue uint64) uint64 { 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 } } @@ -106,7 +106,7 @@ func Uint64(key string, defaultValue uint64) uint64 { func Float32(key string, defaultValue float32) float32 { 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) } } @@ -115,7 +115,7 @@ func Float32(key string, defaultValue float32) float32 { func Float64(key string, defaultValue float64) float64 { 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 } } @@ -124,7 +124,7 @@ func Float64(key string, defaultValue float64) float64 { func Complex64(key string, defaultValue complex64) complex64 { 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) } } @@ -133,7 +133,7 @@ func Complex64(key string, defaultValue complex64) complex64 { func Complex128(key string, defaultValue complex128) complex128 { 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 } } @@ -142,7 +142,7 @@ func Complex128(key string, defaultValue complex128) complex128 { func Bool(key string, defaultValue bool) bool { 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 } }