httplib_version_serve.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
66
package version_server
import (
"encoding/json"
"fmt"
"net/http"
"time"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/log"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/constant"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway"
)
//公共短信服务模块
type HttpLibVersionServer struct {
service_gateway.BaseServiceGateway
baseUrL string
}
func NewHttpLibVersionServer() *HttpLibVersionServer {
return &HttpLibVersionServer{
BaseServiceGateway: service_gateway.BaseServiceGateway{
ConnectTimeout: 100 * time.Second,
ReadWriteTimeout: 30 * time.Second,
},
baseUrL: constant.SUPLUS_ADMIN_BASE_HOST,
}
}
//SendSms 公共短信验证码服务 发送验证码
func (gateway HttpLibVersionServer) GetLatestVersion(rc *http.Request, param ReqLatestVersion) (*DataLatestVersion, error) {
url := gateway.baseUrL + "/version/getLatestVersionInfo"
method := "post"
req := gateway.CreateRequest(url, method)
//TODO traceID
log.Logger.Debug("向版本管理请求数据:搜索用户列表。", map[string]interface{}{
"api": method + ":" + url,
"param": param,
})
req, err := req.JSONBody(param)
if err != nil {
return nil, fmt.Errorf("搜索版本失败:%w", err)
}
for k, vs := range rc.Header {
for i := range vs {
req.Header(k, vs[i])
}
}
byteResult, err := req.Bytes()
if err != nil {
return nil, fmt.Errorf("获取版本失败:%w", err)
}
fmt.Println(string(byteResult))
var result service_gateway.GatewayResponse
err = json.Unmarshal(byteResult, &result)
if err != nil {
return nil, fmt.Errorf("解析版本:%w", err)
}
var data DataLatestVersion
err = gateway.GetResponseData(result, &data)
return &data, err
}