Add function to convert strings to bool

Typically used on boolean environment variable values

Signed-off-by: Ulysses Souza <ulyssessouza@gmail.com>
This commit is contained in:
Ulysses Souza
2022-03-04 16:38:21 +01:00
parent c12a948f97
commit 67b4669f9b
4 changed files with 16 additions and 5 deletions

View File

@@ -16,6 +16,11 @@
package utils
import (
"strconv"
"strings"
)
// StringContains check if an array contains a specific value
func StringContains(array []string, needle string) bool {
for _, val := range array {
@@ -25,3 +30,9 @@ func StringContains(array []string, needle string) bool {
}
return false
}
// StringToBool converts a string to a boolean ignoring errors
func StringToBool(s string) bool {
b, _ := strconv.ParseBool(strings.ToLower(strings.TrimSpace(s)))
return b
}