Files
mayfly-go/server/pkg/httpx/httpx_test.go

36 lines
877 B
Go
Raw Normal View History

2025-04-15 21:42:31 +08:00
package httpx
2023-09-23 22:52:05 +08:00
import (
"fmt"
2023-10-12 12:14:56 +08:00
"mayfly-go/pkg/utils/collx"
2023-09-23 22:52:05 +08:00
"testing"
)
type TestStruct struct {
Id uint64
Username string
}
func TestGet(t *testing.T) {
2025-04-15 21:42:31 +08:00
res, err := NewReq("www.baidu.com").Get().BodyToString()
2023-09-23 22:52:05 +08:00
fmt.Println(err)
fmt.Println(res)
}
func TestGetBodyToMap(t *testing.T) {
2025-04-15 21:42:31 +08:00
res, err := NewReq("http://go.mayfly.run/api/syslogs?pageNum=1&pageSize=10").Get().BodyToMap()
2023-09-23 22:52:05 +08:00
fmt.Println(err)
fmt.Println(res["msg"])
fmt.Println(res["code"])
}
func TestGetQueryBodyToMap(t *testing.T) {
2025-04-15 21:42:31 +08:00
res, err := NewReq("http://go.mayfly.run/api/syslogs").
2023-09-23 22:52:05 +08:00
Header("Authorization", "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2OTUzOTQ5NTIsImlkIjoxLCJ1c2VybmFtZSI6ImFkbWluIn0.pGrczVZqk5nlId-FZPkjW_O5Sw3-2yjgzACp_j4JEXY").
2023-10-12 12:14:56 +08:00
GetByQuery(collx.M{"pageNum": 1, "pageSize": 10}).
2023-09-23 22:52:05 +08:00
BodyToMap()
fmt.Println(err)
fmt.Println(res["msg"])
fmt.Println(res["code"])
}