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 { func (b *Bank) Chain(name string) (c *Chain, ok bool) {
c, _ := b.chains[name] c, ok = b.chains[name]
return c return
} }
func (b *Bank) Reload() { func (b *Bank) Reload() {
@ -77,7 +77,7 @@ func (b *Bank) parse(conf interface{}) *Chain {
} }
case reflect.String: case reflect.String:
name := link.(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) c.Links = append(c.Links, caller)
} else { } else {
fmt.Println("Unknown unit:", name) 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 { if u, ok := b.units[name]; ok {
// Check for unit implementation and create a unit if there is none // Check for unit implementation and create a unit if there is none
if imp := impl.New(u.Name, u.Impl); imp != nil { if imp := impl.New(u.Name, u.Impl); imp != nil {
return imp return imp, true
} else { } else {
return u return u, true
} }
} else { } else {
return nil return nil, false
} }
} }