-
Notifications
You must be signed in to change notification settings - Fork 0
/
handler.go
63 lines (49 loc) · 1.3 KB
/
handler.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
58
59
60
61
62
63
package delayed_job
import (
"errors"
)
type Handler interface {
Perform() error
}
type Updater interface {
UpdatePayloadObject(options map[string]interface{})
}
type MakeHandler func(ctx, options map[string]interface{}) (Handler, error)
var Handlers = map[string]MakeHandler{}
func newHandler(ctx, options map[string]interface{}) (Handler, error) {
t := stringWithDefault(options, "type", "")
if 0 == len(t) {
return nil, errors.New("'type' is required.")
}
makeHandler := Handlers[t]
if nil == makeHandler {
return nil, errors.New("'" + t + "' is unsupported handler")
}
if o := options["attributes"]; o != nil {
if m, ok := o.(map[string]interface{}); ok {
for key, value := range m {
options[key] = value
}
}
}
return makeHandler(ctx, options)
}
var test_chan = make(chan map[string]interface{}, 100)
type testHandler map[string]interface{}
func (self testHandler) Perform() error {
test_chan <- self
e := stringWithDefault(self, "error", "")
if 0 == len(e) {
return nil
}
return errors.New(e)
}
func (self testHandler) UpdatePayloadObject(options map[string]interface{}) {
options["UpdatePayloadObject"] = "UpdatePayloadObject"
}
func newTest(ctx, options map[string]interface{}) (Handler, error) {
return testHandler(options), nil
}
func init() {
Handlers["test"] = newTest
}