...
|
...
|
@@ -3,51 +3,63 @@ package service_gateway |
|
|
import (
|
|
|
"time"
|
|
|
|
|
|
"github.com/astaxie/beego/httplib"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/log"
|
|
|
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain"
|
|
|
)
|
|
|
|
|
|
type HttplibAlliedCreationBasic struct {
|
|
|
connectTimeout time.Duration
|
|
|
readWriteTimeout time.Duration
|
|
|
BaseServiceGateway
|
|
|
BaseUrL string
|
|
|
}
|
|
|
|
|
|
func (gateway HttplibAlliedCreationBasic) createRequest(url string, method string) *httplib.BeegoHTTPRequest {
|
|
|
var request *httplib.BeegoHTTPRequest
|
|
|
switch method {
|
|
|
case "get":
|
|
|
request = httplib.Get(url)
|
|
|
case "post":
|
|
|
request = httplib.Post(url)
|
|
|
case "put":
|
|
|
request = httplib.Put(url)
|
|
|
case "delete":
|
|
|
request = httplib.Delete(url)
|
|
|
case "head":
|
|
|
request = httplib.Head(url)
|
|
|
|
|
|
default:
|
|
|
request = httplib.Get(url)
|
|
|
}
|
|
|
return request.SetTimeout(gateway.connectTimeout, gateway.readWriteTimeout)
|
|
|
var alliedCreationBasicClient = &HttplibAlliedCreationBasic{
|
|
|
BaseServiceGateway: BaseServiceGateway{
|
|
|
connectTimeout: 100 * time.Second,
|
|
|
readWriteTimeout: 30 * time.Second,
|
|
|
},
|
|
|
BaseUrL: "",
|
|
|
}
|
|
|
|
|
|
func (gateway HttplibAlliedCreationBasic) getResponseData(result GatewayResponse) {
|
|
|
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 map[string]interface{}) error {
|
|
|
func (gateway HttplibAlliedCreationBasic) GetDictionarysByCode(param ReqGetDictionarysByCode) (*DataGetDictionarysByCode, error) {
|
|
|
url := gateway.BaseUrL + "/dictionarys/dictionary-code"
|
|
|
req := gateway.createRequest(url, "post")
|
|
|
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 err
|
|
|
return nil, err
|
|
|
}
|
|
|
var result GatewayResponse
|
|
|
err = req.ToJSON(&result)
|
|
|
if err != nil {
|
|
|
return err
|
|
|
return nil, err
|
|
|
}
|
|
|
return nil
|
|
|
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
|
|
|
} |
...
|
...
|
|