|
@@ -19,7 +19,6 @@ var (
|
|
|
|
|
|
FacadeClient = BaseMiniFacade{
|
|
|
client: DefaultClient(),
|
|
|
- data: nil,
|
|
|
}
|
|
|
)
|
|
|
|
|
@@ -33,16 +32,21 @@ func GetInstance(name string) ChartCollect {
|
|
|
}
|
|
|
|
|
|
type ChartCollect interface {
|
|
|
- Collect(data interface{}) (err error)
|
|
|
- UnCollect(data interface{}) (err error)
|
|
|
+ Collect(data BaseRequest) (err error)
|
|
|
+ UnCollect(data BaseRequest) (err error)
|
|
|
+}
|
|
|
+
|
|
|
+type BaseRequest struct {
|
|
|
+ Auth string `json:"auth"`
|
|
|
+ UniqueCode string `json:"uniqueCode"`
|
|
|
}
|
|
|
|
|
|
func (bm *BaseMiniFacade) GetData() interface{} {
|
|
|
return bm.data
|
|
|
}
|
|
|
|
|
|
-func (bm *BaseMiniFacade) Post(url string, data interface{}) (result string, err error) {
|
|
|
- resp, err := bm.client.Post(url, data)
|
|
|
+func (bm *BaseMiniFacade) Post(url string, data interface{}, auth string) (result string, err error) {
|
|
|
+ resp, err := bm.client.Post(url, data, auth)
|
|
|
if err != nil {
|
|
|
return
|
|
|
}
|
|
@@ -54,7 +58,7 @@ func (bm *BaseMiniFacade) Post(url string, data interface{}) (result string, err
|
|
|
result = string(respBody)
|
|
|
return
|
|
|
}
|
|
|
-func (bm *BaseMiniFacade) Deal(data interface{}) *BaseMiniFacade {
|
|
|
+func (bm *BaseMiniFacade) Deal(data BaseRequest) *BaseMiniFacade {
|
|
|
bm.data = data
|
|
|
return bm
|
|
|
}
|
|
@@ -77,7 +81,7 @@ func (bm *BaseMiniFacade) HandleAction(action string, handler ChartCollect) (act
|
|
|
|
|
|
type BaseMiniFacade struct {
|
|
|
client *HttpClient
|
|
|
- data interface{} //返回参数
|
|
|
+ data BaseRequest //返回参数
|
|
|
}
|
|
|
|
|
|
type HttpClient struct {
|
|
@@ -137,7 +141,7 @@ func (hc *HttpClient) DoWithRetry(ctx context.Context, req *http.Request) (resp
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-func (hc *HttpClient) Post(url string, data interface{}) (resp *http.Response, err error) {
|
|
|
+func (hc *HttpClient) Post(url string, data interface{}, auth string) (resp *http.Response, err error) {
|
|
|
dataStr, err := json.Marshal(data)
|
|
|
if err != nil {
|
|
|
utils.FileLog.Error("请求data json序列化失败,err:" + err.Error())
|
|
@@ -145,6 +149,7 @@ func (hc *HttpClient) Post(url string, data interface{}) (resp *http.Response, e
|
|
|
body := io.NopCloser(strings.NewReader(string(dataStr)))
|
|
|
req, err := http.NewRequest(http.MethodPost, url, body)
|
|
|
req.Header.Set("Content-Type", "application/json")
|
|
|
+ req.Header.Set("Authorization", auth)
|
|
|
if err != nil {
|
|
|
utils.FileLog.Error("创建POST请求失败: %v", err.Error())
|
|
|
}
|