-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoptions.go
More file actions
80 lines (67 loc) · 1.8 KB
/
options.go
File metadata and controls
80 lines (67 loc) · 1.8 KB
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
package moneyloverapi
import (
"time"
"go.nhat.io/clock"
"github.com/nhatthm/moneyloverapi/pkg/auth"
)
// WithBaseURL sets API Base URL.
func WithBaseURL(baseURL string) Option {
return func(c *Client) {
c.config.baseURL = baseURL
}
}
// WithTimeout sets API Timeout.
func WithTimeout(timeout time.Duration) Option {
return func(c *Client) {
c.config.timeout = timeout
}
}
// WithUsername sets username to login.
func WithUsername(username string) Option {
return func(c *Client) {
c.config.username = username
}
}
// WithPassword sets password to login.
func WithPassword(password string) Option {
return func(c *Client) {
c.config.password = password
}
}
// WithCredentials sets username and password to login.
func WithCredentials(username string, password string) Option {
return func(c *Client) {
c.config.username = username
c.config.password = password
}
}
// WithCredentialsProvider chains a new credentials provider.
func WithCredentialsProvider(provider CredentialsProvider) Option {
return func(c *Client) {
c.config.credentials.prepend(provider)
}
}
// WithCredentialsProviderAtLast chains a new credentials provider at last position.
func WithCredentialsProviderAtLast(provider CredentialsProvider) Option {
return func(c *Client) {
c.config.credentials.append(provider)
}
}
// WithTokenProvider chains a new token provider.
func WithTokenProvider(provider auth.TokenProvider) Option {
return func(c *Client) {
c.token.prepend(provider)
}
}
// WithTokenStorage sets token storage for the internal apiTokenProvider.
func WithTokenStorage(storage auth.TokenStorage) Option {
return func(c *Client) {
c.config.tokenStorage = storage
}
}
// WithClock sets the clock (for testing purpose).
func WithClock(clock clock.Clock) Option {
return func(c *Client) {
c.clock = clock
}
}