httplib_allied_creation_basic.go
1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package service_gateway
import (
"time"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/log"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain"
)
type HttplibAlliedCreationBasic struct {
BaseServiceGateway
BaseUrL string
}
var alliedCreationBasicClient = &HttplibAlliedCreationBasic{
BaseServiceGateway: BaseServiceGateway{
connectTimeout: 100 * time.Second,
readWriteTimeout: 30 * time.Second,
},
BaseUrL: "",
}
func NewHttplibAlliedCreationBasic() *HttplibAlliedCreationBasic {
return alliedCreationBasicClient
}
//ReqGetDictionarysByCode 根据code获取字典数据
type ReqGetDictionarysByCode struct {
DictCode string `json:"dictCode"`
}
//DataGetDictionarysByCode 根据code获取字典数据
type DataGetDictionarysByCode struct {
Dictionarys []domain.Dictionary `json:"dictionarys"`
}
//GetDictionarysByCode 根据code获取字典数据
func (gateway HttplibAlliedCreationBasic) GetDictionarysByCode(param ReqGetDictionarysByCode) (*DataGetDictionarysByCode, error) {
url := gateway.BaseUrL + "/dictionarys/dictionary-code"
method := "post"
req := gateway.createRequest(url, method)
//TODO traceID
log.Logger.Debug("向基础模块请求数据:根据code获取字典数据。", map[string]interface{}{
"api": method + ":" + url,
"param": param,
})
req, err := req.JSONBody(param)
if err != nil {
return nil, err
}
var result GatewayResponse
err = req.ToJSON(&result)
if err != nil {
return nil, err
}
var data DataGetDictionarysByCode
err = gateway.getResponseData(result, &data)
log.Logger.Debug("获取基础模块响应数据:根据code获取字典数据。", map[string]interface{}{
"code": result.Code,
"msg": result.Msg,
"data": data,
})
return &data, err
}