1
0
Fork 0

Load units

This commit is contained in:
Gregory Eremin 2015-02-11 01:45:59 +07:00
parent 8748c22d6e
commit 5f8329d368
1 changed files with 28 additions and 0 deletions

28
core/units.go Normal file
View File

@ -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,
}
}
}
}