-
Notifications
You must be signed in to change notification settings - Fork 0
/
methods.go
122 lines (100 loc) · 3.44 KB
/
methods.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
package reqgo
import (
"net/http"
)
// Get issues a GET request to the url. If `opt` is not nil, it will be parsed to the request.
func Get(url string, opt *Options) (*Response, error) {
return New(client).Get(url, opt)
}
// Get issues a GET request to the url. If `opt` is not nil, it will be parsed to the request.
func (r *ReqGO) Get(url string, opt *Options) (*Response, error) {
req, err := http.NewRequest(http.MethodGet, url, nil)
if err != nil {
return nil, err
}
return r.doRequest(req, opt)
}
// Post issues a POST request to the url. If `opt` is not nil,
// `opt.Data` will be set as request body and other options will
// be parsed to the request.
func Post(url string, opt *Options) (*Response, error) {
return New(client).Post(url, opt)
}
// Post issues a POST request to the url. If `opt` is not nil,
// `opt.Data` will be set as request body and other options will
// be parsed to the request.
func (r *ReqGO) Post(url string, opt *Options) (*Response, error) {
body, err := parseBody(opt)
if err != nil {
return nil, err
}
req, err := http.NewRequest(http.MethodPost, url, body)
if err != nil {
return nil, err
}
return r.doRequest(req, opt)
}
// Put issues a PUT request to the url. If `opt` is not nil,
// `opt.Data` will be set as request body and other options will
// be parsed to the request.
func Put(url string, opt *Options) (*Response, error) {
return New(client).Put(url, opt)
}
// Put issues a PUT request to the url. If `opt` is not nil,
// `opt.Data` will be set as request body and other options will
// be parsed to the request.
func (r *ReqGO) Put(url string, opt *Options) (*Response, error) {
body, err := parseBody(opt)
if err != nil {
return nil, err
}
req, err := http.NewRequest(http.MethodPut, url, body)
if err != nil {
return nil, err
}
return r.doRequest(req, opt)
}
// Patch issues a PATCH request to the url. If `opt` is not nil,
// `opt.Data` will be set as request body and other options will
// be parsed to the request.
func Patch(url string, opt *Options) (*Response, error) {
return New(client).Patch(url, opt)
}
// Patch issues a PATCH request to the url. If `opt` is not nil,
// `opt.Data` will be set as request body and other options will
// be parsed to the request.
func (r *ReqGO) Patch(url string, opt *Options) (*Response, error) {
body, err := parseBody(opt)
if err != nil {
return nil, err
}
req, err := http.NewRequest(http.MethodPatch, url, body)
if err != nil {
return nil, err
}
return r.doRequest(req, opt)
}
// Delete issues a DELETE request to the url. If `opt` is not nil, it will be parsed to the request.
func Delete(url string, opt *Options) (*Response, error) {
return New(client).Delete(url, opt)
}
// Delete issues a DELETE request to the url. If `opt` is not nil, it will be parsed to the request.
func (r *ReqGO) Delete(url string, opt *Options) (*Response, error) {
req, err := http.NewRequest(http.MethodDelete, url, nil)
if err != nil {
return nil, err
}
return r.doRequest(req, opt)
}
// Head issues a HEAD request to the url. If `opt` is not nil, it will be parsed to the request.
func Head(url string, opt *Options) (*Response, error) {
return New(client).Head(url, opt)
}
// Head issues a HEAD request to the url. If `opt` is not nil, it will be parsed to the request.
func (r *ReqGO) Head(url string, opt *Options) (*Response, error) {
req, err := http.NewRequest(http.MethodHead, url, nil)
if err != nil {
return nil, err
}
return r.doRequest(req, opt)
}