-
Notifications
You must be signed in to change notification settings - Fork 0
/
manthelper.go
76 lines (68 loc) · 2.49 KB
/
manthelper.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
64
65
66
67
68
69
70
71
72
73
74
75
76
package core
// Helper methods for mantles. Operate functionally on Domains, triggering success or
// error callbacks based on the intended functionality. These functions are here to cut down
// on the redundancy of mantles
func MantleSubscribe(d Domain, endpoint string, cb uint64, eb uint64, handler uint64, types []interface{}) {
if err := d.Subscribe(endpoint, handler, types, nil); err != nil {
d.GetApp().CallbackSend(eb, err.Error())
} else {
d.GetApp().CallbackSend(cb)
}
}
func MantleRegister(d Domain, endpoint string, cb uint64, eb uint64, handler uint64, types []interface{}) {
if err := d.Register(endpoint, handler, types, nil); err != nil {
d.GetApp().CallbackSend(eb, err.Error())
} else {
d.GetApp().CallbackSend(cb)
}
}
func MantlePublish(d Domain, endpoint string, cb uint64, eb uint64, args []interface{}) {
if err := d.Publish(endpoint, args, nil); err != nil {
d.GetApp().CallbackSend(eb, err.Error())
} else {
d.GetApp().CallbackSend(cb)
}
}
func MantleCall(d Domain, endpoint string, cb uint64, eb uint64, args []interface{}) {
if results, err := d.Call(endpoint, args, nil); err != nil {
d.RemoveCallExpect(cb)
d.GetApp().CallbackSend(eb, err.Error())
} else {
if types, ok := d.GetCallExpect(cb); !ok && CuminLevel != CuminOff {
// We were never asked for types. Don't do anything
Info("Call for %v received, but no cumin enforcement present.", endpoint)
} else {
d.RemoveCallExpect(cb)
if err := SoftCumin(types, results); err == nil {
d.GetApp().CallbackSend(cb, results...)
} else {
d.GetApp().CallbackSend(eb, err.Error())
}
}
}
}
func MantleUnsubscribe(d Domain, endpoint string, cb uint64, eb uint64) {
if err := d.Unsubscribe(endpoint); err != nil {
d.GetApp().CallbackSend(eb, err.Error())
} else {
d.GetApp().CallbackSend(cb)
}
}
func MantleUnregister(d Domain, endpoint string, cb uint64, eb uint64) {
if err := d.Unregister(endpoint); err != nil {
d.GetApp().CallbackSend(eb, err.Error())
} else {
d.GetApp().CallbackSend(cb)
}
}
// Access the model object functions. Note these methods have identical interfaces
// to allow this one method to do all the heavy lifting
// TODO: implement cuminication of these results
func MantleModel(d Domain, target func(string, map[string]interface{}) ([]interface{}, error),
collection string, query map[string]interface{}, cb uint64, eb uint64) {
if r, err := target(collection, query); err != nil {
d.GetApp().CallbackSend(eb, err.Error())
} else {
d.GetApp().CallbackSend(cb, r...)
}
}