1
0
Fork 0

Implementation has unit name

This commit is contained in:
Gregory Eremin 2015-02-11 19:33:46 +07:00
parent 9e472cc9a3
commit 7f552e5c8a
4 changed files with 9 additions and 6 deletions

View File

@ -2,8 +2,9 @@ package impl
// Implementation of a echo unit
// Comes handy when you need to mock a unit
func Echo() *Impl {
func Echo(name string) *Impl {
return &Impl{
name: name,
actor: func(data []byte) (resp []byte, err error) {
return data, nil
},

View File

@ -2,14 +2,15 @@ package impl
type (
Impl struct {
name string
actor func([]byte) ([]byte, error)
}
)
func New(name string) *Impl {
switch name {
func New(name, impl string) *Impl {
switch impl {
case "units.throttler.Throttler":
return Throttler()
return Throttler(name)
default:
return nil
}

View File

@ -1,7 +1,8 @@
package impl
func Throttler() *Impl {
func Throttler(name string) *Impl {
return &Impl{
name: name,
actor: func(data []byte) (resp []byte, err error) {
return data, nil
},

View File

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