mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
25 lines
395 B
Go
25 lines
395 B
Go
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++ {
|
|
if reflect.DeepEqual(val, s.Index(i).Interface()) == true {
|
|
index = i
|
|
exists = true
|
|
return
|
|
}
|
|
}
|
|
}
|
|
|
|
return
|
|
}
|