1 Star 0 Fork 0

陈志端/jd-union-go-sdk

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
api.go 1.56 KB
一键复制 编辑 原始数据 按行查看 历史
陈志端 提交于 2022-01-25 17:20 +08:00 . 京东联盟Go SDK
package api
import (
"reflect"
)
import (
"gitee.com/changeden/jd-union-go-sdk/common"
"gitee.com/changeden/jd-union-go-sdk/method"
"gitee.com/changeden/jd-union-go-sdk/pkg"
)
// https://union.jd.com/openplatform/api/v2
type api struct {
// 组装Api集合
method.ApiGoodsMethods
method.ApiEffectMethods
method.ApiManageMethods
method.ApiPromotionMethods
method.ApiSellingMethods
method.ApiToolMethods
config *apiConfig
// 方法插件实例数组
_apiMethodPlugins []pkg.ApiMethodPlugin
}
func newApi(config *apiConfig) *api {
inst := &api{
config: config,
}
methodPlugins := getApiMethodPlugin(inst)
inst._apiMethodPlugins = methodPlugins
return inst
}
func getApiMethodPlugin(v *api) []pkg.ApiMethodPlugin {
methodPlugins := make([]pkg.ApiMethodPlugin, 0)
apiValue := reflect.ValueOf(v).Elem()
requestFunc := v.request
var p pkg.ApiMethodPlugin
var canConv bool
for i := 0; i < apiValue.NumField(); i++ {
f := apiValue.Field(i)
if !(f.IsValid() && f.CanInterface()) {
continue
}
if p, canConv = f.Interface().(pkg.ApiMethodPlugin); !canConv {
continue
}
r := f.FieldByName(common.ApiMethodPluginBaseRequestKey)
if !(r.IsValid() && r.CanSet()) {
continue
}
r.Set(reflect.ValueOf(requestFunc))
methodPlugins = append(methodPlugins, p)
}
return methodPlugins
}
func (a *api) request(method *pkg.ApiMethod, params pkg.ApiRequestBody, accessToken *string) (*pkg.ApiResponseDTO, error) {
return NewApiBody(a.config).
SetMethod(method.Method).
SetParamJson(params).
SetAccessToken(accessToken).
Request(method.ResponseWrapKey)
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/changeden/jd-union-go-sdk.git
git@gitee.com:changeden/jd-union-go-sdk.git
changeden
jd-union-go-sdk
jd-union-go-sdk
v0.0.1

搜索帮助