util - add InArray

This commit is contained in:
Mahdi Abu Yasmine 2023-11-10 21:01:31 +01:00
parent 6204d8cffc
commit 0ede0b8df0

View File

@ -127,3 +127,15 @@ func InspectStruct(a any) (map[string]string, bool) {
done = true
return rs, done
}
func InArray(v interface{}, arr interface{}) int {
values := reflect.ValueOf(arr)
if reflect.TypeOf(arr).Kind() == reflect.Slice || values.Len() > 0 {
for i := 0; i < values.Len(); i++ {
if reflect.DeepEqual(v, values.Index(i).Interface()) {
return i
}
}
}
return -1
}