go_goutils/checks/checks.go

50 lines
845 B
Go

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
}