mirror of
https://github.com/replicatedhq/troubleshoot.git
synced 2026-04-15 07:16:34 +00:00
Default BoolString to string and bool to 0 (#211)
* default boolstring to string and bool to 0
This commit is contained in:
committed by
GitHub
parent
54d8d7585d
commit
53626bb025
@@ -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")
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -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"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user