修复用户同步请求数据问题
This commit is contained in:
parent
9d01e83d71
commit
664027a955
|
|
@ -7,7 +7,6 @@ import (
|
|||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
"videoplayer/proto"
|
||||
)
|
||||
|
|
@ -130,6 +129,12 @@ func SyncDataFromMasterReq(url string, token string) proto.UserSync {
|
|||
return userSync
|
||||
}
|
||||
|
||||
type Response struct {
|
||||
Code int `json:"code"`
|
||||
Message string `json:"message"`
|
||||
Data proto.UserSync `json:"data"`
|
||||
}
|
||||
|
||||
// 获取数据,全量及增量
|
||||
func SyncDataFromMasterReq2(url string, data proto.SyncUserReq) (proto.UserSync, error) {
|
||||
defer func() {
|
||||
|
|
@ -160,20 +165,16 @@ func SyncDataFromMasterReq2(url string, data proto.SyncUserReq) (proto.UserSync,
|
|||
}
|
||||
defer resp.Body.Close()
|
||||
//解析数据
|
||||
var m map[string]string
|
||||
err = json.NewDecoder(resp.Body).Decode(&m)
|
||||
responseBod, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
code, _ := strconv.Atoi(m["code"])
|
||||
if code != 0 {
|
||||
return res, err
|
||||
}
|
||||
err = json.Unmarshal([]byte(m["data"]), &res)
|
||||
var response Response
|
||||
err = json.Unmarshal(responseBod, &response)
|
||||
if err != nil {
|
||||
fmt.Println("SyncDataFromMasterReq2 error decode data:", err)
|
||||
return res, err
|
||||
}
|
||||
res = response.Data
|
||||
fmt.Println("SyncDataFromMasterReq2 result add data:", len(res.Add), "update data:", len(res.Update), "delete data:", len(res.Delete))
|
||||
return res, nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue