-
Notifications
You must be signed in to change notification settings - Fork 0
/
http.go
72 lines (60 loc) · 1.57 KB
/
http.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
65
66
67
68
69
70
71
72
package goo_http_request
import (
"io"
)
func New(opts ...Option) *Request {
r := &Request{
Headers: map[string]string{
"Content-Type": CONTENT_TYPE_FORM,
},
}
for _, opt := range opts {
switch opt.Name {
case "tls":
v := opt.Value.(map[string]string)
r.Tls = &Tls{
CaCrtFile: v["caCrtFile"],
ClientCrtFile: v["clientCrtFile"],
ClientKeyFile: v["clientKeyFile"],
}
case "content-type-xml", "content-type-json", "content-type-form":
r.SetHeader("Content-Type", opt.Value.(string))
case "header":
v := opt.Value.(map[string]string)
for field, value := range v {
r.SetHeader(field, value)
}
}
}
return r
}
func Get(url string) ([]byte, error) {
return New().Get(url)
}
func GetWithQuery(url string, data []byte) ([]byte, error) {
return New().GetWithQuery(url, data)
}
func Post(url string, data []byte) ([]byte, error) {
return New().Post(url, data)
}
func PostJson(url string, data []byte) ([]byte, error) {
return New().JsonContentType().Post(url, data)
}
func Put(url string, data []byte) ([]byte, error) {
return New().Put(url, data)
}
func GPTStream(url string, data []byte, cb func(b []byte)) error {
return New().GPTStream(url, data, cb)
}
func Upload(url, fileField, fileName string, fh io.Reader, data map[string]string) (b []byte, err error) {
return New().Upload(url, fileField, fileName, fh, data)
}
func Download(url, filename string) error {
return New().Download(url, filename)
}
func SetHeader(name, value string) *Request {
return New().SetHeader(name, value)
}
func Debug() *Request {
return New().Debug()
}