changed subscription.Message.Data to []byte and added client.Send(m) helper

This commit is contained in:
Gani Georgiev
2023-07-20 16:32:21 +03:00
parent 50d7df45eb
commit ac52befb5b
6 changed files with 76 additions and 22 deletions
+13 -1
View File
@@ -9,7 +9,7 @@ import (
// Message defines a client's channel data.
type Message struct {
Name string
Data string
Data []byte
}
// Client is an interface for a generic subscription client.
@@ -50,6 +50,9 @@ type Client interface {
// IsDiscarded indicates whether the client has been "discarded"
// and should no longer be used.
IsDiscarded() bool
// Send sends the specified message to the client's channel (if not discarded).
Send(m Message)
}
// ensures that DefaultClient satisfies the Client interface
@@ -183,3 +186,12 @@ func (c *DefaultClient) IsDiscarded() bool {
return c.isDiscarded
}
// Send sends the specified message to the client's channel (if not discarded).
func (c *DefaultClient) Send(m Message) {
if c.IsDiscarded() {
return
}
c.Channel() <- m
}