-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathoptions.go
57 lines (46 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
53
54
55
56
57
package work
// GetOpts - iterate the inbound Options and return a struct
func GetOpts(opt ...Option) Options {
opts := getDefaultOptions()
for _, o := range opt {
o(opts)
}
return opts
}
// Option - how Options are passed as arguments
type Option func(Options)
// Options = how options are represented
type Options map[string]interface{}
func getDefaultOptions() Options {
return Options{
optionWithSync: false,
}
}
const optionWithSync = "optionWithSync"
// WithSync optional synchronous execution
func WithSync(sync bool) Option {
return func(o Options) {
o[optionWithSync] = sync
}
}
const optionWithJob = "optionWithJob"
// WithJob optional Job parameter
func WithJob(j *Job) Option {
return func(o Options) {
o[optionWithJob] = j
}
}
const optionWithChannel = "optionWithChannel"
// WithChannel optional channel parameter
func WithChannel(ch interface{}) Option {
return func(o Options) {
o[optionWithChannel] = ch
}
}
// Get a specific option by name
func (o *Options) Get(name string) (interface{}, bool) {
if d, ok := (*o)[name]; ok {
return d, ok
}
return nil, false
}