-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfluentrequest.go
More file actions
53 lines (38 loc) · 806 Bytes
/
fluentrequest.go
File metadata and controls
53 lines (38 loc) · 806 Bytes
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
package fluentrequest
import (
"io"
"net/http"
)
func FluentRequest() *fluentRequest {
return &fluentRequest{
client: http.Client{},
}
}
type fluentRequest struct {
url string
method string
body io.Reader
header http.Header
client http.Client
}
func (r *fluentRequest) Url(url string) *fluentRequest {
r.url = url
return r
}
func (r *fluentRequest) Method(method string) *fluentRequest {
r.method = method
return r
}
func (r *fluentRequest) Body(body io.Reader) *fluentRequest {
r.body = body
return r
}
func (r *fluentRequest) Header(header map[string][]string) *fluentRequest {
r.header = header
return r
}
func (r *fluentRequest) Run() (*http.Response, error) {
req, _ := http.NewRequest(r.method, r.url, r.body)
req.Header = r.header
return r.client.Do(req)
}