feat: add uixt action handler

This commit is contained in:
lilong.129
2024-11-07 20:41:41 +08:00
parent 90358196dd
commit db5768e3a1
3 changed files with 42 additions and 1 deletions

View File

@@ -1 +1 @@
v5.0.0+2411072017
v5.0.0+2411072041

View File

@@ -38,6 +38,9 @@ func NewServer(port int) error {
apiV1PlatformSerial.POST("/stub/login", handleDeviceContext(), loginHandler)
apiV1PlatformSerial.POST("/stub/logout", handleDeviceContext(), logoutHandler)
// run uixt actions
apiV1PlatformSerial.POST("/uixt/action", handleDeviceContext(), uixtActionHandler)
err := router.Run(fmt.Sprintf("127.0.0.1:%d", port))
if err != nil {
log.Err(err).Msg("failed to start http server")

38
hrp/pkg/server/uixt.go Normal file
View File

@@ -0,0 +1,38 @@
package server
import (
"net/http"
"github.com/gin-gonic/gin"
"github.com/httprunner/httprunner/v4/hrp/code"
"github.com/httprunner/httprunner/v4/hrp/pkg/uixt"
"github.com/rs/zerolog/log"
)
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"})
}