Documentation ¶
Overview ¶
Package plugins provides the functionality to subscribe, and publish message according to the plugin.proto. The information are passed in to the plugin via environment variables. The server discovers plugins in the provided plugins folder, and starts these in its context.
Index ¶
- Constants
- Variables
- type Context
- type Event
- type MessageError
- type Opt
- type Opts
- type Plugin
- func (p *Plugin) AsyncReplyWithFunc(fn SubscribeFunc, funcs ...filters.FilterFunc) error
- func (p *Plugin) Log() *log.Entry
- func (p *Plugin) PublishInbox(msg *pb.Message) error
- func (p *Plugin) PublishOutbox(msg *pb.Message) error
- func (p *Plugin) ReplyWithFunc(fn SubscribeFunc, funcs ...filters.FilterFunc) error
- func (p *Plugin) SubscribeInbox(funcs ...filters.FilterFunc) <-chan Event
- func (p *Plugin) SubscribeOutbox(funcs ...filters.FilterFunc) <-chan Event
- func (p *Plugin) Wait() error
- type SubscribeFunc
Examples ¶
Constants ¶
const ( // ErrUnknown ... ErrUnknown = iota // ErrParse ... ErrParse )
Variables ¶
var ( // ErrPluginAuthentication ... ErrPluginAuthentication = errors.New("plugin: failed to authenticate") )
Functions ¶
This section is empty.
Types ¶
type Context ¶
type Context interface { // Message should return the message of the current context. Message() *pb.Message // Send should send a new message with in the current context. Send(*pb.Message) error // AsyncSend should asynchronously send a new message in the current context. AsyncSend(msg *pb.Message) // Context should return the current execution context. Context() context.Context }
Context is providing information and operations upon the reply execution context.
type Event ¶
type Event interface{}
Event symbolizes events that can occur in the plugin. Though they maybe triggered from somewhere else.
type MessageError ¶
MessageError represents an error that may occurs
type Plugin ¶
Plugin describes a plugin in general. It should not be instantiated directly.
Example ¶
ctx, cancel := context.WithCancel(context.Background()) defer cancel() env := runtime.Env() plugin, _ := WithContext(ctx, env) // here you can interact with the plugin data if err := plugin.Wait(); err != nil { panic(err) }
Output:
func WithContext ¶
func WithContext(ctx context.Context, env *runtime.Environment, opts ...Opt) (*Plugin, context.Context)
WithContext is creating a new plugin and a context to run operations in routines. When the context is canceled, all concurrent operations are canceled.
Example ¶
ctx, cancel := context.WithCancel(context.Background()) defer cancel() env := runtime.Env() plugin, _ := WithContext(ctx, env) if err := plugin.Wait(); err != nil { panic(err) }
Output:
func (*Plugin) AsyncReplyWithFunc ¶
func (p *Plugin) AsyncReplyWithFunc(fn SubscribeFunc, funcs ...filters.FilterFunc) error
AsyncReplyWithFunc is a wrapper function to provide a message handler function which will asynchronously reply to the messages received by a plugin. The difference between this and the synchronous ReplyWithFunc wrapper is that while both receive messages in sequence, ReplyWithFunc will block on reading the subsequent message from the inbox while the current message is being handled.
func (*Plugin) PublishInbox ¶
PublishInbox is publishing message to the inbox in the controller.
Example ¶
ctx, cancel := context.WithCancel(context.Background()) defer cancel() env := runtime.Env() plugin, _ := WithContext(ctx, env) msg := &pb.Message{ Text: "foo != bar", } if err := plugin.PublishInbox(msg); err != nil { panic(err) }
Output:
func (*Plugin) PublishOutbox ¶
PublishOutbox is publishing message to the outbox in the controller.
Example ¶
ctx, cancel := context.WithCancel(context.Background()) defer cancel() env := runtime.Env() plugin, _ := WithContext(ctx, env) msg := &pb.Message{ Text: "foo != bar", } if err := plugin.PublishOutbox(msg); err != nil { panic(err) }
Output:
func (*Plugin) ReplyWithFunc ¶
func (p *Plugin) ReplyWithFunc(fn SubscribeFunc, funcs ...filters.FilterFunc) error
ReplyWithFunc is a wrapper function to provide a function which may send replies to received message for this plugin.
Example ¶
ctx, cancel := context.WithCancel(context.Background()) defer cancel() env := runtime.Env() plugin, _ := WithContext(ctx, env) err := plugin.ReplyWithFunc(func(ctx Context) error { log.Printf("received message: %v", ctx.Message()) return nil }) if err != nil { log.Fatal(err) } if err := plugin.Wait(); err != nil { panic(err) }
Output:
func (*Plugin) SubscribeInbox ¶
func (p *Plugin) SubscribeInbox(funcs ...filters.FilterFunc) <-chan Event
SubscribeInbox is subscribing to the inbox of messages. This if for plugins that want to consume the message that other plugins publish to Autobot.
Example ¶
ctx, cancel := context.WithCancel(context.Background()) defer cancel() env := runtime.Env() plugin, rctx := WithContext(ctx, env) for { select { case e := <-plugin.SubscribeInbox(): fmt.Printf("received a new message: %v", e) case <-rctx.Done(): return } }
Output:
func (*Plugin) SubscribeOutbox ¶
func (p *Plugin) SubscribeOutbox(funcs ...filters.FilterFunc) <-chan Event
SubscribeOutbox is subscribing to the outbox of messages. These are the message that ought to be published to an external service (e.g. Slack, MS Teams).
Example ¶
ctx, cancel := context.WithCancel(context.Background()) defer cancel() env := runtime.Env() plugin, rctx := WithContext(ctx, env) for { select { case e := <-plugin.SubscribeOutbox(): fmt.Printf("received message to be send out: %v", e) case <-rctx.Done(): return } }
Output:
func (*Plugin) Wait ¶
Wait is waiting for the underlying WaitGroup. All run go routines are hold here to before one exists with an error. Then the provided context is canceled.
Example ¶
ctx, cancel := context.WithCancel(context.Background()) defer cancel() env := runtime.Env() plugin, _ := WithContext(ctx, env) if err := plugin.Wait(); err != nil { panic(err) }
Output:
Directories ¶
Path | Synopsis |
---|---|
Package filters provides functionality to filter messages.
|
Package filters provides functionality to filter messages. |
Package runtime contains functionality for runtime information of a plugin.
|
Package runtime contains functionality for runtime information of a plugin. |