feat: 更新多个模块以支持新的数据结构和日志格式
This commit is contained in:
@@ -1,12 +1,14 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"be.ems/src/framework/i18n"
|
||||
"be.ems/src/framework/utils/ctx"
|
||||
"be.ems/src/framework/vo/result"
|
||||
"be.ems/src/framework/reqctx"
|
||||
"be.ems/src/framework/resp"
|
||||
traceService "be.ems/src/modules/trace/service"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/gin-gonic/gin/binding"
|
||||
)
|
||||
|
||||
// 实例化控制层 PacketController 结构体
|
||||
@@ -26,85 +28,89 @@ type PacketController struct {
|
||||
// GET /devices
|
||||
func (s *PacketController) Devices(c *gin.Context) {
|
||||
data := s.packetService.NetworkDevices()
|
||||
c.JSON(200, result.OkData(data))
|
||||
c.JSON(200, resp.OkData(data))
|
||||
}
|
||||
|
||||
// 信令跟踪开始
|
||||
//
|
||||
// POST /start
|
||||
func (s *PacketController) Start(c *gin.Context) {
|
||||
language := ctx.AcceptLanguage(c)
|
||||
language := reqctx.AcceptLanguage(c)
|
||||
var body struct {
|
||||
TaskNo string `json:"taskNo" binding:"required"` // 任务编号
|
||||
Device string `json:"device" binding:"required"` // 网卡设备
|
||||
Filter string `json:"filter" ` // 过滤表达式(port 33030 or 33040)
|
||||
OutputPCAP bool `json:"outputPCAP" ` // 输出PCAP文件 (默认false)
|
||||
}
|
||||
if err := c.ShouldBindBodyWith(&body, binding.JSON); err != nil {
|
||||
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||
if err := c.ShouldBindBodyWithJSON(&body); err != nil {
|
||||
errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err))
|
||||
c.JSON(422, resp.CodeMsg(40422, errMsgs))
|
||||
return
|
||||
}
|
||||
|
||||
msg, err := s.packetService.LiveStart(body.TaskNo, body.Device, body.Filter, body.OutputPCAP)
|
||||
if err != nil {
|
||||
c.JSON(200, result.ErrMsg(i18n.TKey(language, err.Error())))
|
||||
c.JSON(200, resp.ErrMsg(i18n.TKey(language, err.Error())))
|
||||
return
|
||||
}
|
||||
c.JSON(200, result.OkData(msg))
|
||||
c.JSON(200, resp.OkData(msg))
|
||||
}
|
||||
|
||||
// 信令跟踪结束
|
||||
//
|
||||
// POST /stop
|
||||
func (s *PacketController) Stop(c *gin.Context) {
|
||||
language := ctx.AcceptLanguage(c)
|
||||
language := reqctx.AcceptLanguage(c)
|
||||
var body struct {
|
||||
TaskNo string `json:"taskNo" binding:"required"` // 任务编号
|
||||
}
|
||||
if err := c.ShouldBindBodyWith(&body, binding.JSON); err != nil {
|
||||
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||
if err := c.ShouldBindBodyWithJSON(&body); err != nil {
|
||||
errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err))
|
||||
c.JSON(422, resp.CodeMsg(40422, errMsgs))
|
||||
return
|
||||
}
|
||||
|
||||
if err := s.packetService.LiveStop(body.TaskNo); err != nil {
|
||||
c.JSON(200, result.ErrMsg(i18n.TKey(language, err.Error())))
|
||||
c.JSON(200, resp.ErrMsg(i18n.TKey(language, err.Error())))
|
||||
return
|
||||
}
|
||||
c.JSON(200, result.Ok(nil))
|
||||
c.JSON(200, resp.Ok(nil))
|
||||
}
|
||||
|
||||
// 信令跟踪过滤
|
||||
//
|
||||
// PUT /filter
|
||||
func (s *PacketController) Filter(c *gin.Context) {
|
||||
language := ctx.AcceptLanguage(c)
|
||||
language := reqctx.AcceptLanguage(c)
|
||||
var body struct {
|
||||
TaskNo string `json:"taskNo" binding:"required"` // 任务编号
|
||||
Expr string `json:"expr" ` // 过滤表达式(port 33030 or 33040)
|
||||
}
|
||||
if err := c.ShouldBindBodyWith(&body, binding.JSON); err != nil {
|
||||
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||
if err := c.ShouldBindBodyWithJSON(&body); err != nil {
|
||||
errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err))
|
||||
c.JSON(422, resp.CodeMsg(40422, errMsgs))
|
||||
return
|
||||
}
|
||||
|
||||
if err := s.packetService.LiveFilter(body.TaskNo, body.Expr); err != nil {
|
||||
c.JSON(200, result.ErrMsg(i18n.TKey(language, err.Error())))
|
||||
c.JSON(200, resp.ErrMsg(i18n.TKey(language, err.Error())))
|
||||
return
|
||||
}
|
||||
c.JSON(200, result.Ok(nil))
|
||||
c.JSON(200, resp.Ok(nil))
|
||||
}
|
||||
|
||||
// 信令跟踪续期保活
|
||||
//
|
||||
// PUT /keep-alive
|
||||
func (s *PacketController) KeepAlive(c *gin.Context) {
|
||||
language := ctx.AcceptLanguage(c)
|
||||
language := reqctx.AcceptLanguage(c)
|
||||
var body struct {
|
||||
TaskNo string `json:"taskNo" binding:"required"` // 任务编号
|
||||
Duration int `json:"duration" ` // 服务失效的时间,默认设置为120秒
|
||||
}
|
||||
if err := c.ShouldBindBodyWith(&body, binding.JSON); err != nil {
|
||||
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||
if err := c.ShouldBindBodyWithJSON(&body); err != nil {
|
||||
errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err))
|
||||
c.JSON(422, resp.CodeMsg(40422, errMsgs))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -114,8 +120,8 @@ func (s *PacketController) KeepAlive(c *gin.Context) {
|
||||
}
|
||||
|
||||
if err := s.packetService.LiveTimeout(body.TaskNo, body.Duration); err != nil {
|
||||
c.JSON(200, result.ErrMsg(i18n.TKey(language, err.Error())))
|
||||
c.JSON(200, resp.ErrMsg(i18n.TKey(language, err.Error())))
|
||||
return
|
||||
}
|
||||
c.JSON(200, result.Ok(nil))
|
||||
c.JSON(200, resp.Ok(nil))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user