go-chat/utils/utils.go

18 lines
297 B
Go
Raw Normal View History

2021-04-22 06:12:35 +00:00
package utils
2021-04-25 01:53:49 +00:00
import "reflect"
func IsContain(elem interface{}, arr interface{}) int {
r := reflect.ValueOf(arr)
k := r.Kind()
if k == reflect.Slice || k == reflect.Array {
l := r.Len()
for i := 0; i < l; i++ {
if r.Index(i).Interface() == elem {
return i
}
}
}
return -1
}