summaryrefslogtreecommitdiff
path: root/plugins/websockets/rpc.go
diff options
context:
space:
mode:
authorValery Piashchynski <[email protected]>2021-05-29 00:24:30 +0300
committerValery Piashchynski <[email protected]>2021-05-29 00:24:30 +0300
commitfcda08498e8f914bbd0798da898818cd5d0e4348 (patch)
tree62d88384d07997e2373f3b273ba0cb83569ebced /plugins/websockets/rpc.go
parent8f13eb958c7eec49acba6e343edb77c6ede89f09 (diff)
- Add new internal plugin - channel. Which used to deliver messages from
the ws plugin to the http directly Signed-off-by: Valery Piashchynski <[email protected]>
Diffstat (limited to 'plugins/websockets/rpc.go')
-rw-r--r--plugins/websockets/rpc.go33
1 files changed, 16 insertions, 17 deletions
diff --git a/plugins/websockets/rpc.go b/plugins/websockets/rpc.go
index f917bd53..2fb0f1b9 100644
--- a/plugins/websockets/rpc.go
+++ b/plugins/websockets/rpc.go
@@ -12,18 +12,17 @@ type rpc struct {
log logger.Logger
}
-func (r *rpc) Publish(msg []*pubsub.Msg, ok *bool) error {
+func (r *rpc) Publish(msg []*pubsub.Message, ok *bool) error {
const op = errors.Op("broadcast_publish")
r.log.Debug("message published", "msg", msg)
- // publish to the registered broker
- mi := make([]pubsub.Message, 0, len(msg))
- // golang can't convert slice in-place
- // so, we need to convert it manually
- for i := 0; i < len(msg); i++ {
- mi = append(mi, msg[i])
+ // just return in case of nil message
+ if msg == nil {
+ *ok = true
+ return nil
}
- err := r.plugin.Publish(mi)
+
+ err := r.plugin.Publish(msg)
if err != nil {
*ok = false
return errors.E(op, err)
@@ -32,16 +31,16 @@ func (r *rpc) Publish(msg []*pubsub.Msg, ok *bool) error {
return nil
}
-func (r *rpc) PublishAsync(msg []*pubsub.Msg, ok *bool) error {
- // publish to the registered broker
- mi := make([]pubsub.Message, 0, len(msg))
- // golang can't convert slice in-place
- // so, we need to convert it manually
- for i := 0; i < len(msg); i++ {
- mi = append(mi, msg[i])
- }
+func (r *rpc) PublishAsync(msg []*pubsub.Message, ok *bool) error {
+ r.log.Debug("message published", "msg", msg)
- r.plugin.PublishAsync(mi)
+ // just return in case of nil message
+ if msg == nil {
+ *ok = true
+ return nil
+ }
+ // publish to the registered broker
+ r.plugin.PublishAsync(msg)
*ok = true
return nil