-
Notifications
You must be signed in to change notification settings - Fork 0
/
request.go
54 lines (43 loc) · 997 Bytes
/
request.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
package facio
type Req struct {
baseURL string
method string
headers map[string]string
formURL map[string][]string
}
// NewRequest receives method and url to create
// a base request to be made
func NewRequest(method, url string) (*Req, error) {
var err error
var r Req
method, err = checkMethod(method)
if err != nil {
return &r, err
}
url, err = parseURL(url)
if err != nil {
return &r, err
}
r = Req{
baseURL: url,
method: method,
headers: make(map[string]string),
formURL: make(map[string][]string),
}
return &r, err
}
// AddHeader add a header into request
func (r *Req) AddHeader(name header, value string) *Req {
r.headers[name.getHeader()] = value
return r
}
// AddCustomHeader add a custom header into request
func (r *Req) AddCustomHeader(name, value string) *Req {
r.headers[name] = value
return r
}
// SetURLForm receives a map with form-value variable
func (r *Req) SetURLForm(vals map[string][]string) *Req {
r.formURL = vals
return r
}