/
registry.go
78 lines (55 loc) · 1.37 KB
/
registry.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
77
78
package action
import (
"fmt"
)
var (
actionFactories = make(map[string]Factory)
// Deprecated: No longer used
actions = make(map[string]Action)
)
func RegisterFactory(ref string, f Factory) error {
if len(ref) == 0 {
return fmt.Errorf("'ref' must be specified when registering an action factory")
}
if f == nil {
return fmt.Errorf("cannot register 'nil' action factory")
}
if actionFactories[ref] != nil {
return fmt.Errorf("action factory already registered for ref '%s'", ref)
}
actionFactories[ref] = f
return nil
}
func GetFactory(ref string) Factory {
return actionFactories[ref]
}
func Factories() map[string]Factory {
//todo return copy
return actionFactories
}
// Deprecated: No longer used
func Get(id string) Action {
return actions[id]
}
// Deprecated: No longer used
func Register(id string, act Action) error {
if len(id) == 0 {
return fmt.Errorf("error registering action, id is empty")
}
if act == nil {
return fmt.Errorf("error registering action for id '%s', action is nil", id)
}
if actions[id] != nil {
return fmt.Errorf("error registering action, action already registered for id '%s'", id)
}
actions[id] = act
return nil
}
// Deprecated: No longer used
func Actions() map[string]Action {
actionsCopy := make(map[string]Action, len(actions))
for id, act := range actions {
actionsCopy[id] = act
}
return actionsCopy
}