Make truthy function less surprising

This commit is contained in:
Lorenzo Bolla
2021-12-16 14:09:46 +01:00
parent 6826efc723
commit b281819cba
2 changed files with 20 additions and 9 deletions
+8 -3
View File
@@ -114,18 +114,23 @@ func runTaskInBackground(name string, resources []string, proc task.Process) (ta
}
func truthy(value interface{}) bool {
if value == nil {
return false
}
switch value.(type) {
case string:
switch strings.ToLower(value.(string)) {
case "y", "yes", "t", "true", "1":
case "n", "no", "f", "false", "0", "off":
return false
default:
return true
}
case int:
return value.(int) == 1
return !(value.(int) == 0)
case bool:
return value.(bool)
}
return false
return true
}
func maybeRunTaskInBackground(c *gin.Context, name string, resources []string, proc task.Process) {