Skip to content

Instantly share code, notes, and snippets.

Keybase proof

I hereby claim:

  • I am ulyc on github.
  • I am ulyc404 (https://keybase.io/ulyc404) on keybase.
  • I have a public key ASDwJPFdOFOdWKBrB_QDv9z34E9vdi8ZTrgMAsZ3r-Sgwgo

To claim this, I am signing this object:

@UlyC
UlyC / isContain.go
Created June 24, 2020 02:05
gplang 判断obj是否在target中,target支持的类型arrary, slice, map
// 判断obj是否在target中,target支持的类型arrary, slice, map
func Contain(target interface{}, obj interface{}) bool {
targetValue := reflect.ValueOf(target)
switch reflect.TypeOf(target).Kind() {
case reflect.Slice, reflect.Array:
for i := 0; i < targetValue.Len(); i++ {
if targetValue.Index(i).Interface() == obj {
return true
}
}