module_block_chain.go
2.2 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
66
67
68
69
70
71
72
package allied_creation_user
import (
"encoding/json"
"fmt"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/constant"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/log"
)
func (gateway HttplibAlliedCreationUser) ListBlockChains(param ReqListBlockChain) (DataListBlockChain, error) {
if !constant.EnableBlockChain || param.Disable {
return []DataListBlockChainItem{}, nil
}
url := gateway.baseUrL + "/block-chains/"
method := "post"
req := gateway.CreateRequest(url, method)
moduleDesc := "获取区块链数据列表"
//TODO traceID
log.Logger.Debug("向用户模块请求数据:"+moduleDesc, map[string]interface{}{
"api": method + ":" + url,
"param": param,
})
req, err := req.JSONBody(param)
if err != nil {
return nil, fmt.Errorf("%v失败:%w", moduleDesc, err)
}
byteResult, err := req.Bytes()
if err != nil {
return nil, fmt.Errorf("%v失败:%w", moduleDesc, err)
}
var result service_gateway.GatewayResponse
err = json.Unmarshal(byteResult, &result)
if err != nil {
return nil, fmt.Errorf("解析错误:%w", err)
}
var data DataListBlockChain
err = gateway.GetResponseData(result, &data)
return data, err
}
func (gateway HttplibAlliedCreationUser) BlockChainsToken(param ReqBlockChainToken) (*DataBlockChainToken, error) {
url := gateway.baseUrL + "/block-chains/token"
method := "post"
req := gateway.CreateRequest(url, method)
moduleDesc := "获取区块链数据授权"
//TODO traceID
log.Logger.Debug("向用户模块请求数据:"+moduleDesc, map[string]interface{}{
"api": method + ":" + url,
"param": param,
})
req, err := req.JSONBody(param)
if err != nil {
return nil, fmt.Errorf("%v失败:%w", moduleDesc, err)
}
byteResult, err := req.Bytes()
if err != nil {
return nil, fmt.Errorf("%v失败:%w", moduleDesc, err)
}
var result service_gateway.GatewayResponse
err = json.Unmarshal(byteResult, &result)
if err != nil {
return nil, fmt.Errorf("解析错误:%w", err)
}
var data DataBlockChainToken
err = gateway.GetResponseData(result, &data)
return &data, err
}