-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.go
52 lines (44 loc) · 1.09 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
package apdata
import (
"log"
"github.com/HereMobilityDevelopers/mediary"
)
type (
ClientOption func(opt ClientOptionsData) ClientOptionsData
ClientOptionsData struct {
logger *log.Logger
interceptors []mediary.Interceptor
debug bool
}
)
func defaultClientOptionsData() ClientOptionsData {
return ClientOptionsData{
logger: log.Default(),
interceptors: make([]mediary.Interceptor, 0),
}
}
func combineOptions(options []ClientOption) ClientOptionsData {
optionsData := defaultClientOptionsData()
for _, opt := range options {
optionsData = opt(optionsData)
}
return optionsData
}
func WithLogger(logger *log.Logger) ClientOption {
return func(opt ClientOptionsData) ClientOptionsData {
opt.logger = logger
return opt
}
}
func WithDebug(debug bool) ClientOption {
return func(opt ClientOptionsData) ClientOptionsData {
opt.debug = debug
return opt
}
}
func WithInterceptors(inter ...mediary.Interceptor) ClientOption {
return func(opt ClientOptionsData) ClientOptionsData {
opt.interceptors = append(opt.interceptors, inter...)
return opt
}
}