-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoptions.go
57 lines (47 loc) · 1.1 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
package oauth
import (
"log"
"github.com/agentstation/egothic"
)
// Options is a function that configures the oauth package.
type Options func(*oauthConfig)
type oauthConfig struct {
debug bool
logger *log.Logger
}
func (c *oauthConfig) apply(opts ...Options) {
for _, opt := range opts {
opt(c)
}
}
func newConfig(opts ...Options) *oauthConfig {
c := &oauthConfig{}
c.apply(opts...)
return c
}
func (c *oauthConfig) toEgothicOptions() []egothic.Options {
eGothicOpts := []egothic.Options{}
if c.debug {
eGothicOpts = append(eGothicOpts, egothic.WithDebug())
}
if c.logger != nil {
eGothicOpts = append(eGothicOpts, egothic.WithLogger(c.logger))
}
return eGothicOpts
}
func optionsToEgothicOptions(opts ...Options) []egothic.Options {
config := newConfig(opts...)
return config.toEgothicOptions()
}
// WithDebug sets the debug mode for the oauth package.
func WithDebug() Options {
return func(c *oauthConfig) {
c.debug = true
}
}
// WithLogger sets the logger for the oauth package.
func WithLogger(logger *log.Logger) Options {
return func(c *oauthConfig) {
c.logger = logger
}
}