Ai
3 Star 2 Fork 0

info-superbahn-ict/superbahn

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
handler_pull.go 1.32 KB
一键复制 编辑 原始数据 按行查看 历史
tangshibo 提交于 2021-12-16 16:19 +08:00 . update
package main
import (
"encoding/json"
"fmt"
"gitee.com/info-superbahn-ict/superbahn/pkg/supbmanager/clireq"
"gitee.com/info-superbahn-ict/superbahn/sync/define"
"github.com/sirupsen/logrus"
"io/ioutil"
"net/http"
)
func (r *WebClientPlugin) pull (w http.ResponseWriter, rq *http.Request) {
// todo init
log := logrus.WithContext(r.ctx).WithFields(logrus.Fields{
define.LogsPrintCommonLabelOfFunction: "plugins.web.server.pull",
})
// todo get data
buffers, err := ioutil.ReadAll(rq.Body)
if err != nil {
responseErr(&w,log,"read body %v",err)
return
}
// todo 解码参数
var req = &clireq.ClientRequest{}
err = json.Unmarshal(buffers,req)
if err != nil {
responseErr(&w,log,"decode bytes %v",err)
}
log.Debugf("receive pull clireq %v", req)
// todo 处理 + return
res,err := r.pullStaticStrategy(req)
if err !=nil {
responseErr(&w,log,"pull info %v",err)
}
resp := &clireq.ClientResponse{
Message: res,
}
bts,err :=json.Marshal(resp)
if err !=nil {
responseErr(&w,log,"marshal %v",err)
}
if bt, err := w.Write(bts); err != nil {
log.Errorf("pull function %v", err)
} else {
log.Infof(fmt.Sprintf("PULL REPONSE (%vB)", bt))
}
}
func (r *WebClientPlugin) pullStaticStrategy(req *clireq.ClientRequest) (string, error) {
return r.api.GetStrategyManager().PullStaticStrategy(req.Names[0])
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/info-superbahn-ict/superbahn.git
git@gitee.com:info-superbahn-ict/superbahn.git
info-superbahn-ict
superbahn
superbahn
5fda629dab96

搜索帮助