访问京东API,获取结账必要信息。

This commit is contained in:
lyb
2018-08-09 16:37:38 +08:00
parent c430b997f9
commit 0ef674c072
4 changed files with 89 additions and 3 deletions

25
business/util/Contain.go Normal file
View File

@@ -0,0 +1,25 @@
package util
import (
"errors"
"reflect"
)
// 判断obj是否在target中target支持的类型arrary,slice,map
func Contain(obj interface{}, target interface{}) (bool, error) {
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, nil
}
}
case reflect.Map:
if targetValue.MapIndex(reflect.ValueOf(obj)).IsValid() {
return true, nil
}
}
return false, errors.New("not in array")
}