diff --git a/checks/checks.go b/checks/checks.go new file mode 100644 index 0000000..7c3d32a --- /dev/null +++ b/checks/checks.go @@ -0,0 +1,49 @@ +package checks + +func All(l []interface{}) (int, bool) { + for idx, i := range l { + switch i.(type) { + case bool: + if i == false { + return idx, false + } + case string: + if i == "" { + return idx, false + } + case int8, int16, int32, int64, uint8, uint16, uint32, uint64, uintptr, float32, float64: + if i == 0 { + return idx, false + } + default: + if i == nil { + return idx, false + } + } + } + return 0, true +} + +func Any(l []interface{}) (int, bool) { + for idx, i := range l { + switch i.(type) { + case bool: + if i == true { + return idx, true + } + case string: + if i != "" { + return idx, true + } + case int8, int16, int32, int64, uint8, uint16, uint32, uint64, uintptr, float32, float64: + if i != 0 { + return idx, true + } + default: + if i != nil { + return idx, true + } + } + } + return 0, false +}