mirror of
https://github.com/httprunner/httprunner.git
synced 2026-08-07 22:53:46 +08:00
refactor: move shoots related server to ext
This commit is contained in:
@@ -8,41 +8,48 @@ import (
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
func NewServer(port int) error {
|
||||
router := gin.Default()
|
||||
router.GET("/ping", pingHandler)
|
||||
func NewRouter() *Router {
|
||||
router := &Router{}
|
||||
router.Init()
|
||||
return router
|
||||
}
|
||||
|
||||
apiV1Platform := router.Group("/api/v1").Group("/:platform")
|
||||
type Router struct {
|
||||
*gin.Engine
|
||||
}
|
||||
|
||||
func (r *Router) Init() {
|
||||
r.Engine = gin.Default()
|
||||
r.Engine.GET("/ping", pingHandler)
|
||||
|
||||
apiV1Platform := r.Engine.Group("/api/v1").Group("/:platform")
|
||||
apiV1Platform.GET("/devices", listDeviceHandler)
|
||||
|
||||
apiV1PlatformSerial := apiV1Platform.Group("/:serial")
|
||||
// UI operations
|
||||
apiV1PlatformSerial.POST("/ui/tap", handleDeviceContext(), tapHandler)
|
||||
apiV1PlatformSerial.POST("/ui/drag", handleDeviceContext(), dragHandler)
|
||||
apiV1PlatformSerial.POST("/ui/input", handleDeviceContext(), inputHandler)
|
||||
apiV1PlatformSerial.POST("/ui/tap", r.HandleDeviceContext(), tapHandler)
|
||||
apiV1PlatformSerial.POST("/ui/drag", r.HandleDeviceContext(), dragHandler)
|
||||
apiV1PlatformSerial.POST("/ui/input", r.HandleDeviceContext(), inputHandler)
|
||||
// Key operations
|
||||
apiV1PlatformSerial.POST("/key/unlock", handleDeviceContext(), unlockHandler)
|
||||
apiV1PlatformSerial.POST("/key/home", handleDeviceContext(), homeHandler)
|
||||
apiV1PlatformSerial.POST("/key", handleDeviceContext(), keycodeHandler)
|
||||
apiV1PlatformSerial.POST("/key/unlock", r.HandleDeviceContext(), unlockHandler)
|
||||
apiV1PlatformSerial.POST("/key/home", r.HandleDeviceContext(), homeHandler)
|
||||
apiV1PlatformSerial.POST("/key", r.HandleDeviceContext(), keycodeHandler)
|
||||
// App operations
|
||||
apiV1PlatformSerial.GET("/app/foreground", handleDeviceContext(), foregroundAppHandler)
|
||||
apiV1PlatformSerial.POST("/app/clear", handleDeviceContext(), clearAppHandler)
|
||||
apiV1PlatformSerial.POST("/app/launch", handleDeviceContext(), launchAppHandler)
|
||||
apiV1PlatformSerial.POST("/app/terminal", handleDeviceContext(), terminalAppHandler)
|
||||
apiV1PlatformSerial.GET("/app/foreground", r.HandleDeviceContext(), foregroundAppHandler)
|
||||
apiV1PlatformSerial.POST("/app/clear", r.HandleDeviceContext(), clearAppHandler)
|
||||
apiV1PlatformSerial.POST("/app/launch", r.HandleDeviceContext(), launchAppHandler)
|
||||
apiV1PlatformSerial.POST("/app/terminal", r.HandleDeviceContext(), terminalAppHandler)
|
||||
// get screen info
|
||||
apiV1PlatformSerial.GET("/screenshot", handleDeviceContext(), screenshotHandler)
|
||||
apiV1PlatformSerial.POST("/screenresult", handleDeviceContext(), screenResultHandler)
|
||||
apiV1PlatformSerial.GET("/shoots/source", handleDeviceContext(), sourceHandler)
|
||||
apiV1PlatformSerial.GET("/adb/source", handleDeviceContext(), adbSourceHandler)
|
||||
// shoots operations
|
||||
apiV1PlatformSerial.POST("/shoots/login", handleDeviceContext(), loginHandler)
|
||||
apiV1PlatformSerial.POST("/shoots/logout", handleDeviceContext(), logoutHandler)
|
||||
|
||||
apiV1PlatformSerial.GET("/screenshot", r.HandleDeviceContext(), screenshotHandler)
|
||||
apiV1PlatformSerial.POST("/screenresult", r.HandleDeviceContext(), screenResultHandler)
|
||||
apiV1PlatformSerial.GET("/adb/source", r.HandleDeviceContext(), adbSourceHandler)
|
||||
// run uixt actions
|
||||
apiV1PlatformSerial.POST("/uixt/action", handleDeviceContext(), uixtActionHandler)
|
||||
apiV1PlatformSerial.POST("/uixt/actions", handleDeviceContext(), uixtActionsHandler)
|
||||
apiV1PlatformSerial.POST("/uixt/action", r.HandleDeviceContext(), uixtActionHandler)
|
||||
apiV1PlatformSerial.POST("/uixt/actions", r.HandleDeviceContext(), uixtActionsHandler)
|
||||
}
|
||||
|
||||
err := router.Run(fmt.Sprintf("127.0.0.1:%d", port))
|
||||
func (r *Router) Run(port int) error {
|
||||
err := r.Engine.Run(fmt.Sprintf("127.0.0.1:%d", port))
|
||||
if err != nil {
|
||||
log.Err(err).Msg("failed to start http server")
|
||||
return err
|
||||
|
||||
Reference in New Issue
Block a user