Documentation
¶
Index ¶
Constants ¶
View Source
const ( // ErrServer tells the client there was a server error ErrServer wsError = "ERR_SERVER" // ErrBadMessage tells the client that the message they sent isn't supported ErrBadMessage wsError = "ERR_BADMESSAGE" ErrUnauthorized wsError = "ERR_UNAUTHORIZED" // ErrInvalidTopic tells the client the topic they sent isn't valid ErrInvalidTopic wsError = "ERR_INVALIDTOPIC" )
View Source
const ( // TypeResponse is used to tell the client they have a response // for an action such as listening or unlistening to topics TypeResponse wsType = "RESPONSE" // TypeMessage tells the client they have a new payload from the server TypeMessage wsType = "MESSAGE" // TypeListen tells the Server that you want to listen to a set topic(s) TypeListen wsType = "LISTEN" // TypeUnlisten tells the Server that you want to unlisten to a set topic(s) TypeUnlisten wsType = "UNLISTEN" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct { Send chan *MessagePayload User *security.User // contains filtered or unexported fields }
Client is a connection to the Instance
func (*Client) RemoveTopics ¶
RemoveTopics removes a topic from a client
type Instance ¶
type Instance struct { Clients map[*Client]bool Inbound chan []byte Register chan *Client Unregister chan *Client Store *redis.Client // contains filtered or unexported fields }
Instance is a pubsub server instance
func (*Instance) AddHandler ¶
AddHandler creates a response function for a given topic
func (*Instance) Handler ¶
func (i *Instance) Handler(w http.ResponseWriter, r *http.Request)
Handler is the websocket upgrade handler
func (*Instance) Publish ¶
func (i *Instance) Publish(topics []string, data *MessagePayload)
Publish publishes a message to all the connected clients listening to a set topic(s)
type MessagePayload ¶
type MessagePayload struct { Type wsType `json:"type"` Nonce string `json:"nonce,omitempty"` Error wsError `json:"error,omitempty"` Data MessagePayloadData `json:"data,omitempty"` }
MessagePayload is the message from clients to the server and server to clients
type MessagePayloadData ¶
type MessagePayloadData struct { Topics []string `json:"topics,omitempty"` Data interface{} `json:"data,omitempty"` }
MessagePayloadData is the main data object of the message payload
Click to show internal directories.
Click to hide internal directories.