-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient_option.go
52 lines (42 loc) · 995 Bytes
/
client_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
47
48
49
50
51
52
package cloudconfig
import "github.com/pkg/errors"
type ClientOption func(c *defaultClient) error
func WithBranch(branch string) ClientOption {
return func(c *defaultClient) error {
if branch == "" {
return errors.New("branch must not be empty")
}
c.branch = branch
return nil
}
}
func WithFormat(format Format) ClientOption {
return func(c *defaultClient) error {
if !format.Valid() {
return errors.Errorf("[%s] is not an acceptable format", format)
}
c.format = format
return nil
}
}
func WithScheme(scheme string) ClientOption {
return func(c *defaultClient) error {
if scheme == "" {
return errors.New("scheme must not be empty")
}
c.scheme = scheme
return nil
}
}
func WithBasicAuth(username, password string) ClientOption {
return func(c *defaultClient) error {
if username == "" {
return errors.New("username must not be empty")
}
c.basicAuth = &basicAuthInfo{
username: username,
password: password,
}
return nil
}
}