-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcallbacks.go
43 lines (35 loc) · 1.02 KB
/
callbacks.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
package croconf
type callbackBinding struct {
apply func() error
}
func (cb *callbackBinding) Apply() error {
return cb.apply()
}
func NewCallbackBinding(callback func() error) Binding {
return &callbackBinding{apply: callback}
}
type callbackBindingFromSource struct {
*callbackBinding
source Source
boundName string
}
func (cbs *callbackBindingFromSource) Source() Source {
return cbs.source
}
func (cbs *callbackBindingFromSource) BoundName() string {
return cbs.boundName
}
func NewCallbackBindingFromSource(source Source, boundName string, callback func() error) BindingFromSource {
return &callbackBindingFromSource{
callbackBinding: &callbackBinding{apply: callback},
source: source,
boundName: boundName,
}
}
func wrapBinding(origBinding Binding, newCallback func() error) Binding {
if fromSource, ok := origBinding.(BindingFromSource); ok {
return NewCallbackBindingFromSource(fromSource.Source(), fromSource.BoundName(), newCallback)
} else {
return NewCallbackBinding(newCallback)
}
}