Create Slice string to bool pointer conversion

This commit is contained in:
wojtekt 2019-10-10 13:24:24 +02:00
parent a7b0f1199b
commit f08dfb4cb6

View File

@ -102,6 +102,27 @@ func Convert_Slice_string_To_bool(in *[]string, out *bool, s conversion.Scope) e
return nil
}
// Convert_Slice_string_To_bool will convert a string parameter to boolean.
// Only the absence of a value (i.e. zero-length slice), a value of "false", or a
// value of "0" resolve to false.
// Any other value (including empty string) resolves to true.
func Convert_Slice_string_To_Pointer_bool(in *[]string, out **bool, s conversion.Scope) error {
if len(*in) == 0 {
boolVar := false
*out = &boolVar
return nil
}
switch {
case (*in)[0] == "0", strings.EqualFold((*in)[0], "false"):
boolVar := false
*out = &boolVar
default:
boolVar := true
*out = &boolVar
}
return nil
}
func string_to_int64(in string) (int64, error) {
return strconv.ParseInt(in, 10, 64)
}