adding ParseBool function
This commit is contained in:
+11
@@ -161,3 +161,14 @@ func NewSettingsWithContext(ctx context.Context, filename string, logUpdates boo
|
||||
go settings.maintenanceRoutine(ctx)
|
||||
return settings
|
||||
}
|
||||
|
||||
func ParseBool(value string) (bool, error) {
|
||||
switch strings.ToLower(strings.TrimSpace(value)) {
|
||||
case "1", "true", "t", "yes", "y", "on":
|
||||
return true, nil
|
||||
case "0", "false", "f", "no", "n", "off":
|
||||
return false, nil
|
||||
default:
|
||||
return false, fmt.Errorf("cannot parse '%s' as bool", value)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user