-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrequest.go
44 lines (37 loc) · 884 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
package tapd
import (
"net/http"
)
type RequestOption func(*http.Request) error
func WithRequestBasicAuth(username, password string) RequestOption {
return func(req *http.Request) error {
req.SetBasicAuth(username, password)
return nil
}
}
func WithRequestHeader(name, value string) RequestOption {
return func(req *http.Request) error {
req.Header.Set(name, value)
return nil
}
}
func WithRequestHeaders(headers map[string]string) RequestOption {
return func(req *http.Request) error {
for k, v := range headers {
req.Header.Set(k, v)
}
return nil
}
}
func WithRequestHeaderFunc(fn func(http.Header)) RequestOption {
return func(req *http.Request) error {
fn(req.Header)
return nil
}
}
func WithRequestUserAgent(userAgent string) RequestOption {
return func(req *http.Request) error {
req.Header.Set("User-Agent", userAgent)
return nil
}
}