MCPcopy Create free account
hub / github.com/LanceLRQ/deer-executor / Contains

Function Contains

common/utils/common.go:8–24  ·  view source on GitHub ↗

Contains 判断数组、切片或Map是否存在某个值

(array interface{}, obj interface{})

Source from the content-addressed store, hash-verified

6
7// Contains 判断数组、切片或Map是否存在某个值
8func Contains(array interface{}, obj interface{}) bool {
9 arrayValue := reflect.ValueOf(array)
10 switch reflect.TypeOf(array).Kind() {
11 case reflect.Slice, reflect.Array:
12 for i := 0; i < arrayValue.Len(); i++ {
13 if arrayValue.Index(i).Interface() == obj {
14 return true
15 }
16 }
17 case reflect.Map:
18 if arrayValue.MapIndex(reflect.ValueOf(obj)).IsValid() {
19 return true
20 }
21 }
22
23 return false
24}

Callers 1

RunTestlibValidatorsFunction · 0.92

Calls

no outgoing calls

Tested by

no test coverage detected