generated from WillAbides/goproject-tmpl
/
options.go
106 lines (88 loc) · 2.13 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package requests
import (
"context"
"net/http"
"net/url"
)
// AuthProvider sets the Authorization header authenticate you with the API
type AuthProvider interface {
AuthorizationHeader(ctx context.Context) (string, error)
}
// Option is a request option
type Option func(opts *Options)
var defaultOptions = Options{
baseURL: url.URL{
Host: "api.github.com",
Scheme: "https",
},
userAgent: "octo-go",
httpClient: http.DefaultClient,
}
// BuildOptions turns a list of opt into *Options
func BuildOptions(opt ...Option) *Options {
result := defaultOptions
for _, o := range opt {
if o == nil {
continue
}
o(&result)
}
return &result
}
// Options is options
type Options struct {
baseURL url.URL
userAgent string
requiredPreviews bool
allPreviews bool
authProvider AuthProvider
httpClient *http.Client
}
// HttpClient return httpClient
func (o *Options) HttpClient() *http.Client {
return o.httpClient
}
// SetHttpClient sets httpClient
func (o *Options) SetHttpClient(httpClient *http.Client) {
o.httpClient = httpClient
}
// AuthProvider returns AuthProvider
func (o *Options) AuthProvider() AuthProvider {
return o.authProvider
}
// SetAuthProvider sets AuthProvider
func (o *Options) SetAuthProvider(authProvider AuthProvider) {
o.authProvider = authProvider
}
// AllPreviews returns bool
func (o *Options) AllPreviews() bool {
return o.allPreviews
}
// SetAllPreviews sets bool
func (o *Options) SetAllPreviews(allPreviews bool) {
o.allPreviews = allPreviews
}
// RequiredPreviews returns bool
func (o *Options) RequiredPreviews() bool {
return o.requiredPreviews
}
// SetRequiredPreviews sets bool
func (o *Options) SetRequiredPreviews(requiredPreviews bool) {
o.requiredPreviews = requiredPreviews
}
// UserAgent returns userAgent
func (o *Options) UserAgent() string {
return o.userAgent
}
// SetUserAgent sets userAgent
func (o *Options) SetUserAgent(userAgent string) {
o.userAgent = userAgent
}
// BaseURL returns baseURL
func (o *Options) BaseURL() url.URL {
return o.baseURL
}
// SetBaseURL sets baseURL
func (o *Options) SetBaseURL(baseURL url.URL) {
o.baseURL = baseURL
}