feat: 接入swagger功能

This commit is contained in:
TsMask
2025-01-07 17:12:35 +08:00
parent bbc2fe5900
commit 92f6ae8787
11 changed files with 1103 additions and 403 deletions

View File

@@ -7,6 +7,8 @@ import (
"runtime"
"strings"
"github.com/gin-gonic/gin"
"be.ems/src/framework/i18n"
"be.ems/src/framework/utils/ctx"
"be.ems/src/framework/utils/file"
@@ -14,8 +16,6 @@ import (
"be.ems/src/framework/utils/ssh"
"be.ems/src/framework/vo/result"
neService "be.ems/src/modules/network_element/service"
"github.com/gin-gonic/gin"
"github.com/gin-gonic/gin/binding"
)
// 实例化控制层 NeActionController 结构体
@@ -34,6 +34,15 @@ type NeActionController struct {
// 从本地到网元发送文件
//
// POST /pushFile
//
// @Tags network_element
// @Accept json
// @Produce json
// @Success 200 {object} map[string]any{} "data"
// @Security ApiKeyAuth
// @Summary Sending files from local to network elements
// @Description Sending files from local to network elements
// @Router /ne/action/pushFile [post]
func (s *NeActionController) PushFile(c *gin.Context) {
language := ctx.AcceptLanguage(c)
var body struct {
@@ -42,7 +51,7 @@ func (s *NeActionController) PushFile(c *gin.Context) {
UploadPath string `json:"uploadPath" binding:"required"`
DelTemp bool `json:"delTemp"` // 删除本地临时文件
}
if err := c.ShouldBindBodyWith(&body, binding.JSON); err != nil {
if err := c.ShouldBindBodyWithJSON(&body); err != nil {
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
return
}
@@ -331,7 +340,7 @@ func (s *NeActionController) Service(c *gin.Context) {
NeID string `json:"neId" binding:"required"`
Action string `json:"action" binding:"required,oneof=start restart stop reboot poweroff"` // 操作行为
}
if err := c.ShouldBindBodyWith(&body, binding.JSON); err != nil {
if err := c.ShouldBindBodyWithJSON(&body); err != nil {
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
return
}