package service
|
|
import (
|
"encoding/json"
|
"gat1400Exchange/config"
|
"gat1400Exchange/models"
|
"gat1400Exchange/pkg/logger"
|
"gat1400Exchange/util"
|
"gat1400Exchange/vo"
|
)
|
|
func ResendImageData() {
|
var cacheMod models.Cache
|
cacheItems, _ := cacheMod.FindAll()
|
|
for _, c := range cacheItems {
|
if !SendData([]byte(c.Data), config.ForwardConf.SyncServer) {
|
logger.Warn("The data resend failed. retry count %d", c.Retry)
|
|
c.Retry = c.Retry + 1
|
c.Update()
|
} else {
|
c.Delete()
|
logger.Debug("The data resend successful.")
|
}
|
}
|
|
}
|
|
func SendData(payload []byte, url string) bool {
|
body, err := util.HttpPost(url, nil, payload)
|
if err != nil {
|
logger.Error("Post request failure, url:%s, err:%s", err.Error())
|
return false
|
}
|
|
var rsp vo.SyncServerResponse
|
err = json.Unmarshal(body, &rsp)
|
if err != nil {
|
logger.Error("Can't parse response, url:%s, rsp: %v", url, body)
|
return false
|
}
|
|
return rsp.Success
|
}
|