refacotr: move pkg/server to root

This commit is contained in:
lilong.129
2025-02-06 11:28:34 +08:00
parent 1f063dd6f7
commit a578e92e00
10 changed files with 2 additions and 2 deletions

70
server/uixt.go Normal file
View File

@@ -0,0 +1,70 @@
package server
import (
"net/http"
"github.com/gin-gonic/gin"
"github.com/httprunner/httprunner/v5/code"
"github.com/httprunner/httprunner/v5/pkg/uixt"
"github.com/rs/zerolog/log"
)
// exec a single uixt action
func uixtActionHandler(c *gin.Context) {
dExt, err := getContextDriver(c)
if err != nil {
return
}
var req uixt.MobileAction
if err := c.ShouldBindJSON(&req); err != nil {
handlerValidateRequestFailedContext(c, err)
return
}
if err = dExt.DoAction(req); err != nil {
log.Err(err).Interface("action", req).
Msg("exec uixt action failed")
c.JSON(http.StatusInternalServerError,
HttpResponse{
Code: code.GetErrorCode(err),
Message: err.Error(),
},
)
c.Abort()
return
}
c.JSON(http.StatusOK, HttpResponse{Code: 0, Message: "success"})
}
// exec multiple uixt actions
func uixtActionsHandler(c *gin.Context) {
dExt, err := getContextDriver(c)
if err != nil {
return
}
var actions []uixt.MobileAction
if err := c.ShouldBindJSON(&actions); err != nil {
handlerValidateRequestFailedContext(c, err)
return
}
for _, action := range actions {
if err = dExt.DoAction(action); err != nil {
log.Err(err).Interface("action", action).
Msg("exec uixt action failed")
c.JSON(http.StatusInternalServerError,
HttpResponse{
Code: code.GetErrorCode(err),
Message: err.Error(),
},
)
c.Abort()
return
}
}
c.JSON(http.StatusOK, HttpResponse{Code: 0, Message: "success"})
}