added a funtion to add a global (plugin) handler
add a function for registering "global" (plugin) handlers.
This commit is contained in:
parent
d0a90addfd
commit
f07e669c0f
@ -41,6 +41,7 @@ func NewClient(ctx context.Context, params RegistrationParams) *Client {
|
|||||||
ctx: ctx,
|
ctx: ctx,
|
||||||
params: params,
|
params: params,
|
||||||
actions: make(map[string]*Action),
|
actions: make(map[string]*Action),
|
||||||
|
handlers: make(map[string][]EventHandler),
|
||||||
done: make(chan struct{}),
|
done: make(chan struct{}),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -204,6 +205,10 @@ func (client *Client) SendToPlugin(ctx context.Context, payload interface{}) err
|
|||||||
return client.send(NewEvent(ctx, SendToPlugin, payload))
|
return client.send(NewEvent(ctx, SendToPlugin, payload))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (client *Client) RegisterHandler(eventName string, handler EventHandler) {
|
||||||
|
client.handlers[eventName] = append(client.handlers[eventName], handler)
|
||||||
|
}
|
||||||
|
|
||||||
func (client *Client) Close() error {
|
func (client *Client) Close() error {
|
||||||
err := client.c.WriteMessage(websocket.CloseMessage, websocket.FormatCloseMessage(websocket.CloseNormalClosure, ""))
|
err := client.c.WriteMessage(websocket.CloseMessage, websocket.FormatCloseMessage(websocket.CloseNormalClosure, ""))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user