forked from grid/firemodel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathregistry.go
36 lines (30 loc) · 754 Bytes
/
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
package firemodel
import "github.com/pkg/errors"
var (
registeredModelers = map[string]Modeler{}
)
func RegisterModeler(name string, m Modeler) {
if _, ok := registeredModelers[name]; ok {
panic(errors.Errorf("firemodel: %s modeler already registered", name))
}
registeredModelers[name] = m
}
type Language struct {
Language string
Output string
}
func AllModelers() (ret []string) {
ret = []string{}
for modelerName := range registeredModelers {
ret = append(ret, modelerName)
}
return ret
}
func (l Language) Modeler() Modeler {
m, ok := registeredModelers[l.Language]
if !ok {
err := errors.Errorf("firemodel: config includes unimplemented language: %s (don't forget to _ import the modeler)", l)
panic(err)
}
return m
}