feat: 新增工具模块 iperf

This commit is contained in:
TsMask
2024-10-09 17:38:32 +08:00
parent 7aae060f2e
commit e3b55c38e5
10 changed files with 221 additions and 0 deletions

View File

@@ -0,0 +1,71 @@
package controller
// https://iperf.fr/iperf-download.php
// https://launchpad.net/ubuntu/jammy/amd64/libsctp1/1.0.19+dfsg-1build1
import (
"strings"
"be.ems/src/framework/i18n"
"be.ems/src/framework/utils/ctx"
"be.ems/src/framework/vo/result"
"be.ems/src/modules/tool/service"
"github.com/gin-gonic/gin"
)
// 实例化控制层 IPerfController 结构体
var NewIPerf = &IPerfController{
iperfService: service.NewIPerf,
}
// iperf 网络性能测试工具
//
// PATH /tool/iperf
type IPerfController struct {
// IPerf3 网络性能测试工具服务
iperfService *service.IPerf
}
// iperf 版本信息
//
// GET /v
func (s *IPerfController) Version(c *gin.Context) {
language := ctx.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")))
return
}
output, err := s.iperfService.Version(query.NeType, query.NeID)
if err != nil {
c.JSON(200, result.ErrMsg(i18n.TKey(language, err.Error())))
return
}
data := strings.Split(output, "\n")
c.JSON(200, result.OkData(data))
}
// iperf 软件安装
//
// GET /i
func (s *IPerfController) Install(c *gin.Context) {
language := ctx.AcceptLanguage(c)
var body struct {
NeType string `json:"neType" binding:"required"` // 网元类型
NeID string `json:"neId" binding:"required"` // 网元ID
}
if err := c.ShouldBindBodyWithJSON(&body); err != nil {
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
return
}
if err := s.iperfService.Install(body.NeType, body.NeID); err != nil {
c.JSON(200, result.ErrMsg(i18n.TKey(language, err.Error())))
return
}
c.JSON(200, result.OkData(nil))
}