do not expose low level message.Message to publish
This commit is contained in:
parent
c8bfbbd8fd
commit
eed039f351
10
client.go
10
client.go
@ -18,8 +18,8 @@ var defaultOpts = options{
|
||||
|
||||
//https://faye.jcoglan.com/architecture.html
|
||||
type client interface {
|
||||
Subscribe(subscription string, onMsg func(message *message.Message)) error
|
||||
Publish(subscription string, message *message.Message) error
|
||||
Subscribe(subscription string, onMsg func(data message.Data)) error
|
||||
Publish(subscription string, data message.Data) error
|
||||
//todo unsubscribe,etc
|
||||
}
|
||||
|
||||
@ -82,10 +82,10 @@ func WithTransport(t transport.Transport) Option {
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Client) Subscribe(subscription string, onMsg func(message *message.Message)) error {
|
||||
func (c *Client) Subscribe(subscription string, onMsg func(message message.Data)) error {
|
||||
return c.opts.transport.Subscribe(subscription, onMsg)
|
||||
}
|
||||
|
||||
func (c *Client) Publish(subscription string, message *message.Message) error {
|
||||
return c.opts.transport.Publish(subscription, message)
|
||||
func (c *Client) Publish(subscription string, data message.Data) error {
|
||||
return c.opts.transport.Publish(subscription, data)
|
||||
}
|
||||
|
@ -4,6 +4,8 @@ import "errors"
|
||||
|
||||
type Extension func(message *Message)
|
||||
|
||||
type Data = interface{}
|
||||
|
||||
type Message struct {
|
||||
Channel string `json:"channel,omitempty"`
|
||||
Version string `json:"version,omitempty"`
|
||||
@ -15,7 +17,7 @@ type Message struct {
|
||||
Id string `json:"id,omitempty"`
|
||||
ClientId string `json:"clientId,omitempty"`
|
||||
Advice Advise `json:"advice,omitempty"`
|
||||
Data interface{} `json:"data,omitempty"`
|
||||
Data Data `json:"data,omitempty"`
|
||||
Timestamp uint64 `json:"timestamp,omitempty"`
|
||||
AuthSuccessful bool `json:"authSuccessful,omitempty"`
|
||||
Error string `json:"error,omitempty"`
|
||||
|
@ -18,9 +18,9 @@ type Transport interface {
|
||||
Options() *Options
|
||||
Handshake() error
|
||||
Connect() error
|
||||
Subscribe(subscription string, onMessage func(message *message.Message)) error
|
||||
Subscribe(subscription string, onMessage func(message message.Data)) error
|
||||
Unsubscribe(subscription string) error
|
||||
Publish(subscription string, message *message.Message) error
|
||||
Publish(subscription string, message message.Data) error
|
||||
}
|
||||
|
||||
type Event = string
|
||||
|
@ -160,7 +160,7 @@ func (w *Websocket) Connect() error {
|
||||
return w.sendMessage(&m)
|
||||
}
|
||||
|
||||
func (w *Websocket) Subscribe(subscription string, onMessage func(message *message.Message)) error {
|
||||
func (w *Websocket) Subscribe(subscription string, onMessage func(data message.Data)) error {
|
||||
m := &message.Message{
|
||||
Channel: transport.Subscribe,
|
||||
ClientId: w.clientID,
|
||||
@ -184,7 +184,7 @@ func (w *Websocket) Subscribe(subscription string, onMessage func(message *messa
|
||||
if inMsg.GetError() != nil {
|
||||
return inMsg.GetError()
|
||||
}
|
||||
onMessage(inMsg)
|
||||
onMessage(inMsg.Data)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@ -200,7 +200,7 @@ func (w *Websocket) Unsubscribe(subscription string) error {
|
||||
return w.sendMessage(m)
|
||||
}
|
||||
|
||||
func (w *Websocket) Publish(subscription string, message *message.Message) error {
|
||||
func (w *Websocket) Publish(subscription string, data message.Data) error {
|
||||
panic("not implemented")
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user