feat: 更新多个模块以支持新的数据结构和日志格式
This commit is contained in:
@@ -8,8 +8,8 @@ import (
|
||||
|
||||
"be.ems/src/framework/i18n"
|
||||
"be.ems/src/framework/logger"
|
||||
"be.ems/src/framework/utils/ctx"
|
||||
"be.ems/src/framework/vo/result"
|
||||
"be.ems/src/framework/reqctx"
|
||||
"be.ems/src/framework/resp"
|
||||
neService "be.ems/src/modules/network_element/service"
|
||||
"be.ems/src/modules/tool/service"
|
||||
wsService "be.ems/src/modules/ws/service"
|
||||
@@ -38,7 +38,7 @@ type IPerfController struct {
|
||||
// @Tags tool/iperf
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param neType query string true "NE Type" Enums(IMS,AMF,AUSF,UDM,SMF,PCF,NSSF,NRF,UPF,MME,CBC,OMC,SGWC)
|
||||
// @Param neType query string true "NE Type" Enums(IMS,AMF,AUSF,UDM,SMF,PCF,NSSF,NRF,UPF,MME,CBC,OMC,SGWC,SMSC)
|
||||
// @Param neId query string true "NE ID" default(001)
|
||||
// @Param version query string true "Version" Enums(V2, V3)
|
||||
// @Success 200 {object} object "Response Results"
|
||||
@@ -47,24 +47,24 @@ type IPerfController struct {
|
||||
// @Description iperf version information
|
||||
// @Router /tool/iperf/v [get]
|
||||
func (s *IPerfController) Version(c *gin.Context) {
|
||||
language := ctx.AcceptLanguage(c)
|
||||
language := reqctx.AcceptLanguage(c)
|
||||
var query struct {
|
||||
NeType string `form:"neType" binding:"required"` // 网元类型
|
||||
NeId string `form:"neId" binding:"required"` // 网元ID
|
||||
Version string `form:"version" binding:"required,oneof=V2 V3"` // 版本
|
||||
}
|
||||
if err := c.ShouldBindQuery(&query); err != nil {
|
||||
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||
c.JSON(400, resp.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||
return
|
||||
}
|
||||
|
||||
output, err := s.iperfService.Version(query.NeType, query.NeId, query.Version)
|
||||
if err != nil {
|
||||
c.JSON(200, result.ErrMsg(i18n.TKey(language, err.Error())))
|
||||
c.JSON(200, resp.ErrMsg(i18n.TKey(language, err.Error())))
|
||||
return
|
||||
}
|
||||
data := strings.Split(output, "\n")
|
||||
c.JSON(200, result.OkData(data))
|
||||
c.JSON(200, resp.OkData(data))
|
||||
}
|
||||
|
||||
// iperf 软件安装
|
||||
@@ -81,22 +81,22 @@ func (s *IPerfController) Version(c *gin.Context) {
|
||||
// @Description iperf software installation
|
||||
// @Router /tool/iperf/i [post]
|
||||
func (s *IPerfController) Install(c *gin.Context) {
|
||||
language := ctx.AcceptLanguage(c)
|
||||
language := reqctx.AcceptLanguage(c)
|
||||
var body struct {
|
||||
NeType string `json:"neType" binding:"required"` // 网元类型
|
||||
NeId string `json:"neId" binding:"required"` // 网元ID
|
||||
Version string `form:"version" binding:"required,oneof=V2 V3"` // 版本
|
||||
}
|
||||
if err := c.ShouldBindBodyWithJSON(&body); err != nil {
|
||||
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||
c.JSON(400, resp.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||
return
|
||||
}
|
||||
|
||||
if err := s.iperfService.Install(body.NeType, body.NeId, body.Version); 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))
|
||||
}
|
||||
|
||||
// iperf 软件运行
|
||||
@@ -106,7 +106,7 @@ func (s *IPerfController) Install(c *gin.Context) {
|
||||
// @Tags tool/iperf
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param neType query string true "NE Type" Enums(IMS,AMF,AUSF,UDM,SMF,PCF,NSSF,NRF,UPF,MME,CBC,OMC,SGWC)
|
||||
// @Param neType query string true "NE Type" Enums(IMS,AMF,AUSF,UDM,SMF,PCF,NSSF,NRF,UPF,MME,CBC,OMC,SGWC,SMSC)
|
||||
// @Param neId query string true "NE ID" default(001)
|
||||
// @Param cols query number false "Terminal line characters" default(120)
|
||||
// @Param rows query number false "Terminal display lines" default(40)
|
||||
@@ -117,7 +117,7 @@ func (s *IPerfController) Install(c *gin.Context) {
|
||||
// @Description (ws://) iperf software running
|
||||
// @Router /tool/iperf/run [get]
|
||||
func (s *IPerfController) Run(c *gin.Context) {
|
||||
language := ctx.AcceptLanguage(c)
|
||||
language := reqctx.AcceptLanguage(c)
|
||||
var query struct {
|
||||
NeType string `form:"neType" binding:"required"` // 网元类型
|
||||
NeId string `form:"neId" binding:"required"` // 网元标识id
|
||||
@@ -125,28 +125,28 @@ func (s *IPerfController) Run(c *gin.Context) {
|
||||
Rows int `form:"rows"` // 终端显示行数
|
||||
}
|
||||
if err := c.ShouldBindQuery(&query); err != nil {
|
||||
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||
c.JSON(400, resp.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||
return
|
||||
}
|
||||
|
||||
// 登录用户信息
|
||||
loginUser, err := ctx.LoginUser(c)
|
||||
loginUser, err := reqctx.LoginUser(c)
|
||||
if err != nil {
|
||||
c.JSON(401, result.CodeMsg(401, i18n.TKey(language, err.Error())))
|
||||
c.JSON(401, resp.CodeMsg(401, i18n.TKey(language, err.Error())))
|
||||
return
|
||||
}
|
||||
|
||||
// 网元主机的SSH客户端
|
||||
sshClient, err := neService.NewNeInfo.NeRunSSHClient(query.NeType, query.NeId)
|
||||
if err != nil {
|
||||
c.JSON(200, result.ErrMsg(err.Error()))
|
||||
c.JSON(200, resp.ErrMsg(err.Error()))
|
||||
return
|
||||
}
|
||||
defer sshClient.Close()
|
||||
// ssh连接会话
|
||||
clientSession, err := sshClient.NewClientSession(query.Cols, query.Rows)
|
||||
if err != nil {
|
||||
c.JSON(200, result.ErrMsg("neinfo ssh client session new err"))
|
||||
c.JSON(200, resp.ErrMsg("neinfo ssh client session new err"))
|
||||
return
|
||||
}
|
||||
defer clientSession.Close()
|
||||
@@ -158,7 +158,7 @@ func (s *IPerfController) Run(c *gin.Context) {
|
||||
}
|
||||
defer wsConn.Close()
|
||||
|
||||
wsClient := s.wsService.ClientCreate(loginUser.UserID, nil, wsConn, clientSession)
|
||||
wsClient := s.wsService.ClientCreate(loginUser.UserId, nil, wsConn, clientSession)
|
||||
go s.wsService.ClientWriteListen(wsClient)
|
||||
go s.wsService.ClientReadListen(wsClient, s.iperfService.Run)
|
||||
|
||||
@@ -175,7 +175,7 @@ func (s *IPerfController) Run(c *gin.Context) {
|
||||
outputByte := clientSession.Read()
|
||||
if len(outputByte) > 0 {
|
||||
outputStr := string(outputByte)
|
||||
msgByte, _ := json.Marshal(result.Ok(map[string]any{
|
||||
msgByte, _ := json.Marshal(resp.Ok(map[string]any{
|
||||
"requestId": fmt.Sprintf("iperf3_%d", ms.UnixMilli()),
|
||||
"data": outputStr,
|
||||
}))
|
||||
@@ -183,7 +183,7 @@ func (s *IPerfController) Run(c *gin.Context) {
|
||||
}
|
||||
case <-wsClient.StopChan: // 等待停止信号
|
||||
s.wsService.ClientClose(wsClient.ID)
|
||||
logger.Infof("ws Stop Client UID %s", wsClient.BindUid)
|
||||
logger.Infof("ws Stop Client UID %d", wsClient.BindUid)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,8 +7,8 @@ import (
|
||||
|
||||
"be.ems/src/framework/i18n"
|
||||
"be.ems/src/framework/logger"
|
||||
"be.ems/src/framework/utils/ctx"
|
||||
"be.ems/src/framework/vo/result"
|
||||
"be.ems/src/framework/reqctx"
|
||||
"be.ems/src/framework/resp"
|
||||
neService "be.ems/src/modules/network_element/service"
|
||||
"be.ems/src/modules/tool/model"
|
||||
"be.ems/src/modules/tool/service"
|
||||
@@ -45,19 +45,19 @@ type PingController struct {
|
||||
// @Description Ping for Basic Information Running
|
||||
// @Router /tool/ping [post]
|
||||
func (s *PingController) Statistics(c *gin.Context) {
|
||||
language := ctx.AcceptLanguage(c)
|
||||
language := reqctx.AcceptLanguage(c)
|
||||
var body model.Ping
|
||||
if err := c.ShouldBindBodyWithJSON(&body); err != nil {
|
||||
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||
c.JSON(400, resp.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||
return
|
||||
}
|
||||
|
||||
info, err := s.pingService.Statistics(body)
|
||||
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(info))
|
||||
c.JSON(200, resp.OkData(info))
|
||||
}
|
||||
|
||||
// ping 传统UNIX运行
|
||||
@@ -74,11 +74,11 @@ func (s *PingController) Statistics(c *gin.Context) {
|
||||
// @Description (ws://) Ping for Local UNIX running
|
||||
// @Router /tool/ping [get]
|
||||
func (s *PingController) StatisticsOn(c *gin.Context) {
|
||||
language := ctx.AcceptLanguage(c)
|
||||
language := reqctx.AcceptLanguage(c)
|
||||
// 登录用户信息
|
||||
loginUser, err := ctx.LoginUser(c)
|
||||
loginUser, err := reqctx.LoginUser(c)
|
||||
if err != nil {
|
||||
c.JSON(401, result.CodeMsg(401, i18n.TKey(language, err.Error())))
|
||||
c.JSON(401, resp.CodeMsg(401, i18n.TKey(language, err.Error())))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -89,14 +89,14 @@ func (s *PingController) StatisticsOn(c *gin.Context) {
|
||||
}
|
||||
defer wsConn.Close()
|
||||
|
||||
wsClient := s.wsService.ClientCreate(loginUser.UserID, nil, wsConn, nil)
|
||||
wsClient := s.wsService.ClientCreate(loginUser.UserId, nil, wsConn, nil)
|
||||
go s.wsService.ClientWriteListen(wsClient)
|
||||
go s.wsService.ClientReadListen(wsClient, s.pingService.StatisticsOn)
|
||||
|
||||
// 等待停止信号
|
||||
for value := range wsClient.StopChan {
|
||||
s.wsService.ClientClose(wsClient.ID)
|
||||
logger.Infof("ws Stop Client UID %s %s", wsClient.BindUid, value)
|
||||
logger.Infof("ws Stop Client UID %d %s", wsClient.BindUid, value)
|
||||
return
|
||||
}
|
||||
}
|
||||
@@ -108,7 +108,7 @@ func (s *PingController) StatisticsOn(c *gin.Context) {
|
||||
// @Tags tool/ping
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param neType query string true "NE Type" Enums(IMS,AMF,AUSF,UDM,SMF,PCF,NSSF,NRF,UPF,MME,CBC,OMC,SGWC)
|
||||
// @Param neType query string true "NE Type" Enums(IMS,AMF,AUSF,UDM,SMF,PCF,NSSF,NRF,UPF,MME,CBC,OMC,SGWC,SMSC)
|
||||
// @Param neId query string true "NE ID" default(001)
|
||||
// @Success 200 {object} object "Response Results"
|
||||
// @Security TokenAuth
|
||||
@@ -116,22 +116,22 @@ func (s *PingController) StatisticsOn(c *gin.Context) {
|
||||
// @Description Ping for version information on the network element side
|
||||
// @Router /tool/ping/v [get]
|
||||
func (s *PingController) Version(c *gin.Context) {
|
||||
language := ctx.AcceptLanguage(c)
|
||||
language := reqctx.AcceptLanguage(c)
|
||||
var query struct {
|
||||
NeType string `form:"neType" binding:"required"` // 网元类型
|
||||
NeID string `form:"neId" binding:"required"` // 网元ID
|
||||
}
|
||||
if err := c.ShouldBindQuery(&query); err != nil {
|
||||
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||
c.JSON(400, resp.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||
return
|
||||
}
|
||||
|
||||
output, err := s.pingService.Version(query.NeType, query.NeID)
|
||||
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(output))
|
||||
c.JSON(200, resp.OkData(output))
|
||||
}
|
||||
|
||||
// ping 网元端UNIX运行
|
||||
@@ -141,7 +141,7 @@ func (s *PingController) Version(c *gin.Context) {
|
||||
// @Tags tool/ping
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param neType query string true "NE Type" Enums(IMS,AMF,AUSF,UDM,SMF,PCF,NSSF,NRF,UPF,MME,CBC,OMC,SGWC)
|
||||
// @Param neType query string true "NE Type" Enums(IMS,AMF,AUSF,UDM,SMF,PCF,NSSF,NRF,UPF,MME,CBC,OMC,SGWC,SMSC)
|
||||
// @Param neId query string true "NE ID" default(001)
|
||||
// @Param cols query number false "Terminal line characters" default(120)
|
||||
// @Param rows query number false "Terminal display lines" default(40)
|
||||
@@ -152,7 +152,7 @@ func (s *PingController) Version(c *gin.Context) {
|
||||
// @Description (ws://) Ping for UNIX runs on the network element side
|
||||
// @Router /tool/ping/run [get]
|
||||
func (s *PingController) Run(c *gin.Context) {
|
||||
language := ctx.AcceptLanguage(c)
|
||||
language := reqctx.AcceptLanguage(c)
|
||||
var query struct {
|
||||
NeType string `form:"neType" binding:"required"` // 网元类型
|
||||
NeId string `form:"neId" binding:"required"` // 网元标识id
|
||||
@@ -160,28 +160,28 @@ func (s *PingController) Run(c *gin.Context) {
|
||||
Rows int `form:"rows"` // 终端显示行数
|
||||
}
|
||||
if err := c.ShouldBindQuery(&query); err != nil {
|
||||
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||
c.JSON(400, resp.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||
return
|
||||
}
|
||||
|
||||
// 登录用户信息
|
||||
loginUser, err := ctx.LoginUser(c)
|
||||
loginUser, err := reqctx.LoginUser(c)
|
||||
if err != nil {
|
||||
c.JSON(401, result.CodeMsg(401, i18n.TKey(language, err.Error())))
|
||||
c.JSON(401, resp.CodeMsg(401, i18n.TKey(language, err.Error())))
|
||||
return
|
||||
}
|
||||
|
||||
// 网元主机的SSH客户端
|
||||
sshClient, err := neService.NewNeInfo.NeRunSSHClient(query.NeType, query.NeId)
|
||||
if err != nil {
|
||||
c.JSON(200, result.ErrMsg(err.Error()))
|
||||
c.JSON(200, resp.ErrMsg(err.Error()))
|
||||
return
|
||||
}
|
||||
defer sshClient.Close()
|
||||
// ssh连接会话
|
||||
clientSession, err := sshClient.NewClientSession(query.Cols, query.Rows)
|
||||
if err != nil {
|
||||
c.JSON(200, result.ErrMsg("neinfo ssh client session new err"))
|
||||
c.JSON(200, resp.ErrMsg("neinfo ssh client session new err"))
|
||||
return
|
||||
}
|
||||
defer clientSession.Close()
|
||||
@@ -193,7 +193,7 @@ func (s *PingController) Run(c *gin.Context) {
|
||||
}
|
||||
defer wsConn.Close()
|
||||
|
||||
wsClient := s.wsService.ClientCreate(loginUser.UserID, nil, wsConn, clientSession)
|
||||
wsClient := s.wsService.ClientCreate(loginUser.UserId, nil, wsConn, clientSession)
|
||||
go s.wsService.ClientWriteListen(wsClient)
|
||||
go s.wsService.ClientReadListen(wsClient, s.pingService.Run)
|
||||
|
||||
@@ -210,7 +210,7 @@ func (s *PingController) Run(c *gin.Context) {
|
||||
outputByte := clientSession.Read()
|
||||
if len(outputByte) > 0 {
|
||||
outputStr := string(outputByte)
|
||||
msgByte, _ := json.Marshal(result.Ok(map[string]any{
|
||||
msgByte, _ := json.Marshal(resp.Ok(map[string]any{
|
||||
"requestId": fmt.Sprintf("ping_%d", ms.UnixMilli()),
|
||||
"data": outputStr,
|
||||
}))
|
||||
@@ -218,7 +218,7 @@ func (s *PingController) Run(c *gin.Context) {
|
||||
}
|
||||
case <-wsClient.StopChan: // 等待停止信号
|
||||
s.wsService.ClientClose(wsClient.ID)
|
||||
logger.Infof("ws Stop Client UID %s", wsClient.BindUid)
|
||||
logger.Infof("ws Stop Client UID %d", wsClient.BindUid)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,8 +9,8 @@ import (
|
||||
|
||||
"be.ems/src/framework/config"
|
||||
"be.ems/src/framework/logger"
|
||||
"be.ems/src/framework/utils/ssh"
|
||||
"be.ems/src/framework/vo/result"
|
||||
"be.ems/src/framework/resp"
|
||||
"be.ems/src/framework/ssh"
|
||||
neService "be.ems/src/modules/network_element/service"
|
||||
wsModel "be.ems/src/modules/ws/model"
|
||||
)
|
||||
@@ -137,8 +137,8 @@ func (s *IPerf) Run(client *wsModel.WSClient, reqMsg wsModel.WSRequest) {
|
||||
// 必传requestId确认消息
|
||||
if reqMsg.RequestID == "" {
|
||||
msg := "message requestId is required"
|
||||
logger.Infof("ws IPerf Run UID %s err: %s", client.BindUid, msg)
|
||||
msgByte, _ := json.Marshal(result.ErrMsg(msg))
|
||||
logger.Infof("ws IPerf Run UID %d err: %s", client.BindUid, msg)
|
||||
msgByte, _ := json.Marshal(resp.ErrMsg(msg))
|
||||
client.MsgChan <- msgByte
|
||||
return
|
||||
}
|
||||
@@ -149,7 +149,7 @@ func (s *IPerf) Run(client *wsModel.WSClient, reqMsg wsModel.WSRequest) {
|
||||
switch reqMsg.Type {
|
||||
case "close":
|
||||
// 主动关闭
|
||||
resultByte, _ := json.Marshal(result.OkMsg("user initiated closure"))
|
||||
resultByte, _ := json.Marshal(resp.OkMsg("user initiated closure"))
|
||||
client.MsgChan <- resultByte
|
||||
// 等待1s后关闭连接
|
||||
time.Sleep(1 * time.Second)
|
||||
@@ -184,8 +184,8 @@ func (s *IPerf) Run(client *wsModel.WSClient, reqMsg wsModel.WSRequest) {
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
logger.Warnf("ws IPerf Run UID %s err: %s", client.BindUid, err.Error())
|
||||
msgByte, _ := json.Marshal(result.ErrMsg(err.Error()))
|
||||
logger.Warnf("ws IPerf Run UID %d err: %s", client.BindUid, err.Error())
|
||||
msgByte, _ := json.Marshal(resp.ErrMsg(err.Error()))
|
||||
client.MsgChan <- msgByte
|
||||
if err == io.EOF {
|
||||
// 等待1s后关闭连接
|
||||
|
||||
@@ -8,8 +8,8 @@ import (
|
||||
"time"
|
||||
|
||||
"be.ems/src/framework/logger"
|
||||
"be.ems/src/framework/utils/ssh"
|
||||
"be.ems/src/framework/vo/result"
|
||||
"be.ems/src/framework/resp"
|
||||
"be.ems/src/framework/ssh"
|
||||
neService "be.ems/src/modules/network_element/service"
|
||||
"be.ems/src/modules/tool/model"
|
||||
wsModel "be.ems/src/modules/ws/model"
|
||||
@@ -47,8 +47,8 @@ func (s *Ping) StatisticsOn(client *wsModel.WSClient, reqMsg wsModel.WSRequest)
|
||||
// 必传requestId确认消息
|
||||
if reqMsg.RequestID == "" {
|
||||
msg := "message requestId is required"
|
||||
logger.Infof("ws Commont UID %s err: %s", client.BindUid, msg)
|
||||
msgByte, _ := json.Marshal(result.ErrMsg(msg))
|
||||
logger.Infof("ws Commont UID %d err: %s", client.BindUid, msg)
|
||||
msgByte, _ := json.Marshal(resp.ErrMsg(msg))
|
||||
client.MsgChan <- msgByte
|
||||
return
|
||||
}
|
||||
@@ -59,7 +59,7 @@ func (s *Ping) StatisticsOn(client *wsModel.WSClient, reqMsg wsModel.WSRequest)
|
||||
switch reqMsg.Type {
|
||||
case "close":
|
||||
// 主动关闭
|
||||
resultByte, _ := json.Marshal(result.OkMsg("user initiated closure"))
|
||||
resultByte, _ := json.Marshal(resp.OkMsg("user initiated closure"))
|
||||
client.MsgChan <- resultByte
|
||||
// 等待1s后关闭连接
|
||||
time.Sleep(1 * time.Second)
|
||||
@@ -81,7 +81,7 @@ func (s *Ping) StatisticsOn(client *wsModel.WSClient, reqMsg wsModel.WSRequest)
|
||||
|
||||
// 接收的数据包
|
||||
pinger.OnRecv = func(pkt *probing.Packet) {
|
||||
resultByte, _ := json.Marshal(result.Ok(map[string]any{
|
||||
resultByte, _ := json.Marshal(resp.Ok(map[string]any{
|
||||
"requestId": reqMsg.RequestID,
|
||||
"data": fmt.Sprintf("%d bytes from %s: icmp_seq=%d time=%v\\r\\n", pkt.Nbytes, pkt.IPAddr, pkt.Seq, pkt.Rtt),
|
||||
}))
|
||||
@@ -89,7 +89,7 @@ func (s *Ping) StatisticsOn(client *wsModel.WSClient, reqMsg wsModel.WSRequest)
|
||||
}
|
||||
// 已接收过的数据包
|
||||
pinger.OnDuplicateRecv = func(pkt *probing.Packet) {
|
||||
resultByte, _ := json.Marshal(result.Ok(map[string]any{
|
||||
resultByte, _ := json.Marshal(resp.Ok(map[string]any{
|
||||
"requestId": reqMsg.RequestID,
|
||||
"data": fmt.Sprintf("%d bytes from %s: icmp_seq=%d time=%v ttl=%v (DUP!)\\r\\n", pkt.Nbytes, pkt.IPAddr, pkt.Seq, pkt.Rtt, pkt.TTL),
|
||||
}))
|
||||
@@ -100,13 +100,13 @@ func (s *Ping) StatisticsOn(client *wsModel.WSClient, reqMsg wsModel.WSRequest)
|
||||
end1 := fmt.Sprintf("\\r\\n--- %s ping statistics ---\\r\\n", stats.Addr)
|
||||
end2 := fmt.Sprintf("%d packets transmitted, %d packets received, %v%% packet loss\\r\\n", stats.PacketsSent, stats.PacketsRecv, stats.PacketLoss)
|
||||
end3 := fmt.Sprintf("round-trip min/avg/max/stddev = %v/%v/%v/%v\\r\\n", stats.MinRtt, stats.AvgRtt, stats.MaxRtt, stats.StdDevRtt)
|
||||
resultByte, _ := json.Marshal(result.Ok(map[string]any{
|
||||
resultByte, _ := json.Marshal(resp.Ok(map[string]any{
|
||||
"requestId": reqMsg.RequestID,
|
||||
"data": fmt.Sprintf("%s%s%s", end1, end2, end3),
|
||||
}))
|
||||
client.MsgChan <- resultByte
|
||||
}
|
||||
resultByte, _ := json.Marshal(result.Ok(map[string]any{
|
||||
resultByte, _ := json.Marshal(resp.Ok(map[string]any{
|
||||
"requestId": reqMsg.RequestID,
|
||||
"data": fmt.Sprintf("PING %s (%s) %d bytes of data.\\r\\n", pinger.Addr(), pinger.IPAddr(), pinger.Size),
|
||||
}))
|
||||
@@ -120,8 +120,8 @@ func (s *Ping) StatisticsOn(client *wsModel.WSClient, reqMsg wsModel.WSRequest)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
logger.Warnf("ws ping run UID %s err: %s", client.BindUid, err.Error())
|
||||
msgByte, _ := json.Marshal(result.ErrMsg(err.Error()))
|
||||
logger.Warnf("ws ping run UID %d err: %s", client.BindUid, err.Error())
|
||||
msgByte, _ := json.Marshal(resp.ErrMsg(err.Error()))
|
||||
client.MsgChan <- msgByte
|
||||
if err == io.EOF {
|
||||
// 等待1s后关闭连接
|
||||
@@ -150,8 +150,8 @@ func (s *Ping) Run(client *wsModel.WSClient, reqMsg wsModel.WSRequest) {
|
||||
// 必传requestId确认消息
|
||||
if reqMsg.RequestID == "" {
|
||||
msg := "message requestId is required"
|
||||
logger.Infof("ws ping run UID %s err: %s", client.BindUid, msg)
|
||||
msgByte, _ := json.Marshal(result.ErrMsg(msg))
|
||||
logger.Infof("ws ping run UID %d err: %s", client.BindUid, msg)
|
||||
msgByte, _ := json.Marshal(resp.ErrMsg(msg))
|
||||
client.MsgChan <- msgByte
|
||||
return
|
||||
}
|
||||
@@ -162,7 +162,7 @@ func (s *Ping) Run(client *wsModel.WSClient, reqMsg wsModel.WSRequest) {
|
||||
switch reqMsg.Type {
|
||||
case "close":
|
||||
// 主动关闭
|
||||
resultByte, _ := json.Marshal(result.OkMsg("user initiated closure"))
|
||||
resultByte, _ := json.Marshal(resp.OkMsg("user initiated closure"))
|
||||
client.MsgChan <- resultByte
|
||||
// 等待1s后关闭连接
|
||||
time.Sleep(1 * time.Second)
|
||||
@@ -197,8 +197,8 @@ func (s *Ping) Run(client *wsModel.WSClient, reqMsg wsModel.WSRequest) {
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
logger.Warnf("ws ping run UID %s err: %s", client.BindUid, err.Error())
|
||||
msgByte, _ := json.Marshal(result.ErrMsg(err.Error()))
|
||||
logger.Warnf("ws ping run UID %d err: %s", client.BindUid, err.Error())
|
||||
msgByte, _ := json.Marshal(resp.ErrMsg(err.Error()))
|
||||
client.MsgChan <- msgByte
|
||||
if err == io.EOF {
|
||||
// 等待1s后关闭连接
|
||||
|
||||
Reference in New Issue
Block a user