diff --git a/core/units.go b/core/units.go new file mode 100644 index 0000000..6307dd1 --- /dev/null +++ b/core/units.go @@ -0,0 +1,28 @@ +package core + +import ( + "encoding/json" + + "github.com/localhots/yeast/impl" + "github.com/localhots/yeast/unit" +) + +var ( + Units = map[string]Caller{} +) + +func LoadUnits(b []byte) { + var conf map[string]map[string]interface{} + json.Unmarshal(b, &conf) + + for name, meta := range conf { + // Check for unit implementation and create a unit if there is none + if imp := impl.New(meta["impl"].(string)); imp != nil { + Units[name] = imp + } else { + Units[name] = &unit.Unit{ + Name: name, + } + } + } +}