-
-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathclient.go
48 lines (38 loc) · 770 Bytes
/
client.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
package rek
import (
"context"
"net/http"
)
func buildClient(opts *options) *http.Client {
var cl *http.Client
if opts.client != nil {
cl = opts.client
} else {
if opts.oauth2Cfg != nil {
cfg, tok := opts.oauth2Cfg.config, opts.oauth2Cfg.token
cl = cfg.Client(getCtx(opts), tok)
} else {
c := &http.Client{}
if opts.cookieJar != nil {
c.Jar = *opts.cookieJar
}
if opts.timeout != 0 {
c.Timeout = opts.timeout
}
if opts.disallowRedirects {
c.CheckRedirect = func(_ *http.Request, _ []*http.Request) error {
return http.ErrUseLastResponse
}
}
cl = c
}
}
return cl
}
func getCtx(opts *options) context.Context {
if opts.ctx == nil {
return context.Background()
} else {
return opts.ctx
}
}