Default BoolString to string and bool to 0 (#211)

* default boolstring to string and bool to 0
This commit is contained in:
Salah Aldeen Al Saleh
2020-06-01 14:55:33 -07:00
committed by GitHub
parent 54d8d7585d
commit 53626bb025
3 changed files with 12 additions and 4 deletions

View File

@@ -28,6 +28,10 @@ func isExcluded(excludeVal multitype.BoolOrString) (bool, error) {
return excludeVal.BoolVal, nil
}
if excludeVal.StrVal == "" {
return false, nil
}
parsed, err := strconv.ParseBool(excludeVal.StrVal)
if err != nil {
return false, errors.Wrap(err, "failed to parse bool string")

View File

@@ -32,6 +32,10 @@ func isExcluded(excludeVal multitype.BoolOrString) (bool, error) {
return excludeVal.BoolVal, nil
}
if excludeVal.StrVal == "" {
return false, nil
}
parsed, err := strconv.ParseBool(excludeVal.StrVal)
if err != nil {
return false, errors.Wrap(err, "failed to parse bool string")

View File

@@ -28,8 +28,8 @@ type BoolOrString struct {
type BoolOrStringType int
const (
Bool BoolOrStringType = iota // The BoolOrString holds an bool.
String // The BoolOrString holds a string.
String BoolOrStringType = iota // The BoolOrString holds a string.
Bool // The BoolOrString holds an bool.
)
// FromBool creates an BoolOrString object with a bool value.
@@ -57,14 +57,14 @@ func (boolstr *BoolOrString) UnmarshalJSON(value []byte) error {
return json.Unmarshal(value, &boolstr.BoolVal)
}
// String returns the string value, '1' for true, or '' for false.
// String returns the string value, '1' for true, or '0' for false.
func (boolstr *BoolOrString) String() string {
if boolstr.Type == String {
return boolstr.StrVal
} else if boolstr.BoolVal {
return "1"
} else {
return ""
return "0"
}
}