forked from ideazxy/requests
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi.go
46 lines (35 loc) · 1020 Bytes
/
api.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
package requests
import (
"net/url"
)
var DefaultUserAgent = "Go Requests"
func Request(method, url string) *HttpRequest {
var r = NewRequest(method, url)
r.SetHeader("User-Agent", DefaultUserAgent)
r.SetHeader("Accept", "*/*")
return r
}
func Get(url string) *HttpRequest {
return Request("GET", url)
}
func Post(url string, data interface{}, bodyType string) *HttpRequest {
return Request("POST", url).SetBody(data, bodyType)
}
func PostForm(u string, data url.Values) *HttpRequest {
return Request("POST", u).SetBody(data.Encode(), "application/x-www-form-urlencoded")
}
func Put(url string, data interface{}, bodyType string) *HttpRequest {
return Request("PUT", url).SetBody(data, bodyType)
}
func Head(url string) *HttpRequest {
return Request("HEAD", url)
}
func Options(url string) *HttpRequest {
return Request("OPTIONS", url)
}
func Patch(url string, data interface{}) *HttpRequest {
return Request("PATCH", url)
}
func Delete(url string) *HttpRequest {
return Request("DELETE", url)
}