util - add InArray
This commit is contained in:
parent
6204d8cffc
commit
0ede0b8df0
12
util/util.go
12
util/util.go
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user