-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoptions.go
More file actions
42 lines (35 loc) · 786 Bytes
/
options.go
File metadata and controls
42 lines (35 loc) · 786 Bytes
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
package regcmd
import (
"context"
"fmt"
)
type options struct {
loggerFunc func(s string)
contextGenFunc func() context.Context
pool chan struct{}
}
type CommandOption func(o *options)
func WithContextGeneration(cgf func() context.Context) CommandOption {
return func(o *options) {
o.contextGenFunc = cgf
}
}
func WithLoggerFunc(lf func(s string)) CommandOption {
return func(o *options) {
o.loggerFunc = lf
}
}
func WithPoolSize(psize uint) CommandOption {
return func(o *options) {
o.pool = make(chan struct{}, psize)
}
}
var defaultOptions []CommandOption = []CommandOption{
WithLoggerFunc(func(s string) {
fmt.Println("regcmd: ", s)
}),
WithContextGeneration(func() context.Context {
return context.Background()
}),
WithPoolSize(1),
}