-
Notifications
You must be signed in to change notification settings - Fork 1
/
client_test.go
64 lines (54 loc) · 1.25 KB
/
client_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package xhttp
import (
"context"
"log"
"os"
"testing"
"github.com/go-pay/bm"
)
type HttpGet struct {
Code int `json:"code"`
Message string `json:"message"`
Data any `json:"data,omitempty"`
}
var ctx = context.Background()
func TestHttpGet(t *testing.T) {
client := NewClient()
// test
_, bs, err := client.Req().Get("http://www.baidu.com").EndBytes(ctx)
if err != nil {
log.Println(err)
return
}
log.Println(string(bs))
//rsp := new(HttpGet)
//_, err = client.Type(TypeJSON).Get("http://api.igoogle.ink/app/v1/ping").EndStruct(ctx, rsp)
//if err != nil {
// log.Println(err)
// return
//}
//log.Println(rsp)
}
func TestHttpUploadFile(t *testing.T) {
fileContent, err := os.ReadFile("logo.png")
if err != nil {
log.Println(err)
return
}
bmm := make(bm.BodyMap)
bmm.SetBodyMap("meta", func(bm bm.BodyMap) {
bm.Set("filename", "123.jpg").
Set("sha256", "ad4465asd4fgw5q")
}).SetFormFile("image", &bm.File{Name: "logo.png", Content: fileContent})
client := NewClient()
rsp := new(HttpGet)
_, err = client.Req(TypeMultipartFormData).
Post("http://localhost:2233/admin/v1/oss/uploadImage").
SendMultipartBodyMap(bmm).
EndStruct(ctx, rsp)
if err != nil {
log.Println(err)
return
}
log.Printf("%+v", rsp)
}