1
0
Fork 0

Better caller factoring

This commit is contained in:
Gregory Eremin 2015-02-12 02:49:04 +07:00
parent d991f1abb5
commit db1829f9ed
2 changed files with 8 additions and 8 deletions

View File

@ -26,9 +26,9 @@ func NewBank(config string, units *unit.Bank) *Bank {
}
}
func (b *Bank) Chain(name string) *Chain {
c, _ := b.chains[name]
return c
func (b *Bank) Chain(name string) (c *Chain, ok bool) {
c, ok = b.chains[name]
return
}
func (b *Bank) Reload() {
@ -77,7 +77,7 @@ func (b *Bank) parse(conf interface{}) *Chain {
}
case reflect.String:
name := link.(string)
if caller := b.units.Unit(name); caller != nil {
if caller, ok := b.units.Unit(name); ok {
c.Links = append(c.Links, caller)
} else {
fmt.Println("Unknown unit:", name)

View File

@ -22,16 +22,16 @@ func NewBank(config string) *Bank {
}
}
func (b *Bank) Unit(name string) Caller {
func (b *Bank) Unit(name string) (c Caller, ok bool) {
if u, ok := b.units[name]; ok {
// Check for unit implementation and create a unit if there is none
if imp := impl.New(u.Name, u.Impl); imp != nil {
return imp
return imp, true
} else {
return u
return u, true
}
} else {
return nil
return nil, false
}
}