-
Notifications
You must be signed in to change notification settings - Fork 60
/
Copy pathoptions.go
67 lines (63 loc) · 1.26 KB
/
options.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
55
56
57
58
59
60
61
62
63
64
65
66
67
package goz
import (
"crypto/tls"
"strings"
"time"
)
// Options object
type Options struct {
Debug bool
BaseURI string
Timeout float32
timeout time.Duration
Query interface{}
Headers map[string]interface{}
Cookies interface{}
FormParams map[string]interface{}
JSON interface{}
XML interface{}
Multipart []FormData
Proxy string
Certificates []tls.Certificate
}
func mergeOptions(opts0 Options, opts ...Options) Options {
for _, opt := range opts {
if opt.Debug {
opts0.Debug = opt.Debug
}
if strings.HasPrefix(opt.BaseURI, "http") {
opts0.BaseURI = opt.BaseURI
}
if opt.Timeout > 0 {
opts0.Timeout = opt.Timeout
}
if opt.Query != nil {
opts0.Query = opt.Query
}
if opt.Headers != nil {
opts0.Headers = opt.Headers
}
if opt.Cookies != nil {
opts0.Cookies = opt.Cookies
}
if opt.FormParams != nil {
opts0.FormParams = opt.FormParams
}
if opt.JSON != nil {
opts0.JSON = opt.JSON
}
if opt.XML != nil {
opts0.XML = opt.XML
}
if opt.Multipart != nil {
opts0.Multipart = opt.Multipart
}
if opt.Proxy != "" {
opts0.Proxy = opt.Proxy
}
if opt.Certificates != nil {
opts0.Certificates = opt.Certificates
}
}
return opts0
}