diff --git a/impl/echo.go b/impl/echo.go index 61df394..2f58807 100644 --- a/impl/echo.go +++ b/impl/echo.go @@ -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 }, diff --git a/impl/impl.go b/impl/impl.go index d458ca3..7f7b3b6 100644 --- a/impl/impl.go +++ b/impl/impl.go @@ -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 } diff --git a/impl/throttler.go b/impl/throttler.go index ed94fa3..84ad014 100644 --- a/impl/throttler.go +++ b/impl/throttler.go @@ -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 }, diff --git a/unit/bank.go b/unit/bank.go index a7766d3..20d1e5a 100644 --- a/unit/bank.go +++ b/unit/bank.go @@ -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