neko/server/internal/utils/array.go

25 lines
387 B
Go
Raw Normal View History

2020-01-19 12:30:09 +13:00
package utils
import (
"reflect"
)
func ArrayIn(val interface{}, array interface{}) (exists bool, index int) {
exists = false
index = -1
switch reflect.TypeOf(array).Kind() {
case reflect.Slice:
s := reflect.ValueOf(array)
for i := 0; i < s.Len(); i++ {
2021-07-23 06:58:15 +12:00
if reflect.DeepEqual(val, s.Index(i).Interface()) {
2020-01-19 12:30:09 +13:00
index = i
exists = true
return
}
}
}
return
}