-
Notifications
You must be signed in to change notification settings - Fork 0
/
initiator.go
40 lines (35 loc) · 936 Bytes
/
initiator.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
package util
import (
"fmt"
"sort"
)
var Initiators = map[string]modulelist{}
func CleanInitiators() {
Initiators = map[string]modulelist{}
}
func RegisterInitiator(module string, Name string, handler func()) {
var position string
lines := GetStackLines(8, 9)
if len(lines) == 1 {
position = fmt.Sprintf("%s\r\n", lines[0])
}
if _, ok := Initiators[module]; ok == false {
Initiators[module] = []Module{}
}
Initiators[module] = append(Initiators[module], Module{Name: Name, Handler: handler, Position: position})
}
func InitOrderByName(module string) {
var initiators modulelist
var ok bool
if initiators, ok = Initiators[module]; ok == false {
return
}
sort.Sort(initiators)
for k := range initiators {
DebugPrintf("Herb-go util debug: Init module function %s/%s.\r\n", module, initiators[k].Name)
if initiators[k].Position != "" {
DebugPrint(initiators[k].Position)
}
initiators[k].Handler()
}
}