mirror of
https://github.com/httprunner/httprunner.git
synced 2026-09-06 16:07:45 +08:00
fix: format code
This commit is contained in:
@@ -43,7 +43,6 @@ func NewServer(port int) error {
|
|||||||
|
|
||||||
func pingHandler(c *gin.Context) {
|
func pingHandler(c *gin.Context) {
|
||||||
c.JSON(http.StatusOK, HttpResponse{Result: true})
|
c.JSON(http.StatusOK, HttpResponse{Result: true})
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func listDeviceHandler(c *gin.Context) {
|
func listDeviceHandler(c *gin.Context) {
|
||||||
@@ -143,7 +142,6 @@ func tapHandler(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
c.JSON(http.StatusOK, HttpResponse{Result: true})
|
c.JSON(http.StatusOK, HttpResponse{Result: true})
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func dragHandler(c *gin.Context) {
|
func dragHandler(c *gin.Context) {
|
||||||
@@ -181,7 +179,6 @@ func dragHandler(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
c.JSON(http.StatusOK, HttpResponse{Result: true})
|
c.JSON(http.StatusOK, HttpResponse{Result: true})
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func inputHandler(c *gin.Context) {
|
func inputHandler(c *gin.Context) {
|
||||||
@@ -209,7 +206,6 @@ func inputHandler(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
c.JSON(http.StatusOK, HttpResponse{Result: true})
|
c.JSON(http.StatusOK, HttpResponse{Result: true})
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func unlockHandler(c *gin.Context) {
|
func unlockHandler(c *gin.Context) {
|
||||||
@@ -230,7 +226,6 @@ func unlockHandler(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
c.JSON(http.StatusOK, HttpResponse{Result: true})
|
c.JSON(http.StatusOK, HttpResponse{Result: true})
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func homeHandler(c *gin.Context) {
|
func homeHandler(c *gin.Context) {
|
||||||
@@ -251,7 +246,6 @@ func homeHandler(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
c.JSON(http.StatusOK, HttpResponse{Result: true})
|
c.JSON(http.StatusOK, HttpResponse{Result: true})
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func keycodeHandler(c *gin.Context) {
|
func keycodeHandler(c *gin.Context) {
|
||||||
@@ -279,7 +273,6 @@ func keycodeHandler(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
c.JSON(http.StatusOK, HttpResponse{Result: true})
|
c.JSON(http.StatusOK, HttpResponse{Result: true})
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func foregroundAppHandler(c *gin.Context) {
|
func foregroundAppHandler(c *gin.Context) {
|
||||||
@@ -300,7 +293,6 @@ func foregroundAppHandler(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
c.JSON(http.StatusOK, HttpResponse{Result: appInfo})
|
c.JSON(http.StatusOK, HttpResponse{Result: appInfo})
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func clearAppHandler(c *gin.Context) {
|
func clearAppHandler(c *gin.Context) {
|
||||||
@@ -329,7 +321,6 @@ func clearAppHandler(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
c.JSON(http.StatusOK, HttpResponse{Result: true})
|
c.JSON(http.StatusOK, HttpResponse{Result: true})
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func launchAppHandler(c *gin.Context) {
|
func launchAppHandler(c *gin.Context) {
|
||||||
@@ -357,7 +348,6 @@ func launchAppHandler(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
c.JSON(http.StatusOK, HttpResponse{Result: true})
|
c.JSON(http.StatusOK, HttpResponse{Result: true})
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func terminalAppHandler(c *gin.Context) {
|
func terminalAppHandler(c *gin.Context) {
|
||||||
@@ -385,7 +375,6 @@ func terminalAppHandler(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
c.JSON(http.StatusOK, HttpResponse{Result: true})
|
c.JSON(http.StatusOK, HttpResponse{Result: true})
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func screenshotHandler(c *gin.Context) {
|
func screenshotHandler(c *gin.Context) {
|
||||||
@@ -407,7 +396,6 @@ func screenshotHandler(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
c.JSON(http.StatusOK, HttpResponse{Result: base64.StdEncoding.EncodeToString(raw.Bytes())})
|
c.JSON(http.StatusOK, HttpResponse{Result: base64.StdEncoding.EncodeToString(raw.Bytes())})
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func sourceHandler(c *gin.Context) {
|
func sourceHandler(c *gin.Context) {
|
||||||
@@ -436,7 +424,6 @@ func sourceHandler(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
c.JSON(http.StatusOK, HttpResponse{Result: source})
|
c.JSON(http.StatusOK, HttpResponse{Result: source})
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func adbSourceHandler(c *gin.Context) {
|
func adbSourceHandler(c *gin.Context) {
|
||||||
@@ -463,7 +450,6 @@ func adbSourceHandler(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
c.JSON(http.StatusOK, HttpResponse{Result: source})
|
c.JSON(http.StatusOK, HttpResponse{Result: source})
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func loginHandler(c *gin.Context) {
|
func loginHandler(c *gin.Context) {
|
||||||
@@ -492,7 +478,6 @@ func loginHandler(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
c.JSON(http.StatusOK, HttpResponse{Result: true})
|
c.JSON(http.StatusOK, HttpResponse{Result: true})
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func logoutHandler(c *gin.Context) {
|
func logoutHandler(c *gin.Context) {
|
||||||
@@ -521,7 +506,6 @@ func logoutHandler(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
c.JSON(http.StatusOK, HttpResponse{Result: true})
|
c.JSON(http.StatusOK, HttpResponse{Result: true})
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseDeviceInfo() gin.HandlerFunc {
|
func parseDeviceInfo() gin.HandlerFunc {
|
||||||
|
|||||||
@@ -1,11 +1,8 @@
|
|||||||
package uixt
|
package uixt
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"encoding/binary"
|
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
@@ -133,87 +130,6 @@ func (sad *ShootsAndroidDriver) sendCommand(packageName string, cmdType string,
|
|||||||
return resultMap["Result"], nil
|
return resultMap["Result"], nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sad *ShootsAndroidDriver) send(data []byte, readTimeout ...time.Duration) (map[string]interface{}, error) {
|
|
||||||
timeout := sad.timeout
|
|
||||||
if len(readTimeout) > 0 {
|
|
||||||
timeout = readTimeout[0]
|
|
||||||
}
|
|
||||||
_ = sad.socket.SetReadDeadline(time.Now().Add(timeout))
|
|
||||||
|
|
||||||
err := _send(sad.socket, append(data, '\n'))
|
|
||||||
if err != nil {
|
|
||||||
sad.close()
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
raw, err := _readAll(sad.socket)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
var result map[string]interface{}
|
|
||||||
if err := json.Unmarshal(raw, &result); err != nil {
|
|
||||||
log.Printf("error when parse json response: %s\n", raw)
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return result, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func _send(writer io.Writer, msg []byte) (err error) {
|
|
||||||
for totalSent := 0; totalSent < len(msg); {
|
|
||||||
var sent int
|
|
||||||
if sent, err = writer.Write(msg[totalSent:]); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if sent == 0 {
|
|
||||||
return errors.New("socket connection broken")
|
|
||||||
}
|
|
||||||
totalSent += sent
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func _readN(reader io.Reader, size int) (raw []byte, err error) {
|
|
||||||
raw = make([]byte, 0, size)
|
|
||||||
for len(raw) < size {
|
|
||||||
buf := make([]byte, size-len(raw))
|
|
||||||
var n int
|
|
||||||
if n, err = io.ReadFull(reader, buf); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
if n == 0 {
|
|
||||||
return nil, errors.New("socket connection broken")
|
|
||||||
}
|
|
||||||
raw = append(raw, buf...)
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func _readAll(reader io.Reader) (raw []byte, err error) {
|
|
||||||
buffer := new(bytes.Buffer)
|
|
||||||
for true {
|
|
||||||
lengthBuf := make([]byte, 4)
|
|
||||||
_, err := io.ReadFull(reader, lengthBuf)
|
|
||||||
if err != nil {
|
|
||||||
if err == io.EOF {
|
|
||||||
return buffer.Bytes(), nil
|
|
||||||
} else if errors.Is(err, io.ErrUnexpectedEOF) {
|
|
||||||
err = fmt.Errorf("reached unexpected EOF, read partial data: %s %v", string(buffer.Bytes()), err)
|
|
||||||
return nil, err
|
|
||||||
} else {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
length := binary.BigEndian.Uint32(lengthBuf)
|
|
||||||
|
|
||||||
data, err := _readN(reader, int(length)-4)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
buffer.Write(data)
|
|
||||||
|
|
||||||
}
|
|
||||||
return buffer.Bytes(), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (sad *ShootsAndroidDriver) DeleteSession() error {
|
func (sad *ShootsAndroidDriver) DeleteSession() error {
|
||||||
return sad.close()
|
return sad.close()
|
||||||
}
|
}
|
||||||
@@ -340,42 +256,3 @@ func (sad *ShootsAndroidDriver) isLogin(packageName string) (login bool, err err
|
|||||||
}
|
}
|
||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sad *ShootsAndroidDriver) isLoginBak(packageName string) (login bool, err error) {
|
|
||||||
params := map[string]interface{}{
|
|
||||||
"ClassName": "com.ss.android.ugc.aweme.account.AccountProxyService",
|
|
||||||
"Method": "userService",
|
|
||||||
"RetType": "",
|
|
||||||
"Args": []string{},
|
|
||||||
"CacheObject": true,
|
|
||||||
}
|
|
||||||
id, err := sad.sendCommand(packageName, "CallStaticMethod", params)
|
|
||||||
if err != nil {
|
|
||||||
return false, err
|
|
||||||
}
|
|
||||||
|
|
||||||
params = map[string]interface{}{
|
|
||||||
"ClassName": "com.ss.android.ugc.aweme.account.service.IAccountUserService",
|
|
||||||
"Method": "isLogin",
|
|
||||||
"RetType": "",
|
|
||||||
"Args": []string{},
|
|
||||||
"ObjectId": int(id.(float64)),
|
|
||||||
}
|
|
||||||
loginObj, err := sad.sendCommand(packageName, "CallMethod", params)
|
|
||||||
if err != nil {
|
|
||||||
return false, err
|
|
||||||
}
|
|
||||||
return loginObj.(bool), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func calculatePortNumber(packageName string) int {
|
|
||||||
asciiSum := 0
|
|
||||||
for _, char := range packageName {
|
|
||||||
asciiSum += int(char)
|
|
||||||
}
|
|
||||||
|
|
||||||
portRange := 65536 - 30000
|
|
||||||
calculatedPortNumber := (asciiSum % portRange) + 30000
|
|
||||||
|
|
||||||
return calculatedPortNumber
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user