-
Notifications
You must be signed in to change notification settings - Fork 16
/
option.go
46 lines (38 loc) · 853 Bytes
/
option.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 gohttp
import (
"net/http"
"time"
)
// Option is an interface of request option
type Option interface {
apply(*Request)
}
// OptionFunc is an implementation of option interface
type OptionFunc func(*Request)
func (fn OptionFunc) apply(r *Request) {
fn(r)
}
// SetClient option sets client c for request
func SetClient(c *http.Client) OptionFunc {
return func(r *Request) {
r.client = c
}
}
// SetTransport option sets Transport t for request
func SetTransport(t *http.Transport) OptionFunc {
return func(r *Request) {
r.transport = t
}
}
// SetCookieJar option sets cookie c for request
func SetCookieJar(c http.CookieJar) OptionFunc {
return func(r *Request) {
r.cookie = c
}
}
// SetTimeout option sets timeout t for request
func SetTimeout(t time.Duration) OptionFunc {
return func(r *Request) {
r.timeout = t
}
}