diff --git a/app/app.go b/app/app.go index 0d7a0d9..3a4dbd0 100644 --- a/app/app.go +++ b/app/app.go @@ -47,7 +47,7 @@ func step(ctx lib.Context, sig <-chan os.Signal) bool { //ctx.LogInfo("Dispatcher stopped", m.Map{}) return false } - //ctx.HandleMsg(&msg) + //ctx.HandleMsg(msg) } return true } diff --git a/config/config.go b/config/config.go index 85c6cec..a963534 100644 --- a/config/config.go +++ b/config/config.go @@ -20,6 +20,7 @@ func Start(ctx lib.Context) { type Base struct { name string starter lib.StartProc + actions []lib.ActionConfig children []lib.Config } @@ -31,6 +32,10 @@ func (cfg *Base) Starter() lib.StartProc { return cfg.starter } +func (cfg *Base) Actions() []lib.ActionConfig { + return cfg.actions +} + func (cfg *Base) Children() []lib.Config { return cfg.children } @@ -43,6 +48,7 @@ func MakeBase(name string, starter lib.StartProc) *Base { return &Base{ name: name, starter: starter, + actions: nil, } } diff --git a/lib/lib.go b/lib/lib.go index 8f302ce..158e8e4 100644 --- a/lib/lib.go +++ b/lib/lib.go @@ -1,3 +1,5 @@ +// Package `lib` provides a set of common types (mostly interfaces +// and function declarations) and some basic functions. package lib import ( @@ -5,15 +7,24 @@ import ( "sync" ) +type ActionSpec interface { + Handler() ActionHandler + Receivers() []string +} + +type ActionConfig interface { + Pattern() string + Specs() []ActionSpec +} + type Config interface { Name() string Starter() StartProc + Actions() []ActionConfig Children() []Config Add(Config) } -type Message interface{} - type Services map[string]Context type ContextState interface{} @@ -31,8 +42,18 @@ type Context interface { Stop() } +type Message interface{} + +type Action interface { + Context() Context + Spec() ActionSpec + Message() Message +} + type Proc = func(Context) type StartProc = Proc +type MessageHandler = func(Context, Message) +type ActionHandler = func(Action) // async Runners