Implementation has unit name
This commit is contained in:
parent
9e472cc9a3
commit
7f552e5c8a
|
@ -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
|
||||
},
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
},
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue