Documentation
¶
Index ¶
Constants ¶
View Source
const ( // BodyError Message Body map typ for errors BodyError = "error" // BodySet Message Body map typ for set values BodySet = "set" // BodyGet Message Body map typ for get values BodyGet = "get" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Message ¶
type Message struct {
Type string `json:"type"`
ID *uuid.UUID `json:"id,omitempty"`
ReplyID *uuid.UUID `json:"reply_id,omitempty"`
Body map[string]interface{} `json:"body"`
Subscriber *Subscriber `json:"-"`
}
Message on websocket
type MessageHandleFunc ¶
MessageHandleFunc for handling messages
type Subscriber ¶
type Subscriber struct {
// contains filtered or unexported fields
}
Subscriber of websocket endpoint
type SubscriberEventFunc ¶
type SubscriberEventFunc func(s *Subscriber, msg chan<- *Message)
SubscriberEventFunc for handling connection state of Subsriber
type WebsocketEndpoint ¶
type WebsocketEndpoint struct {
Subscribers map[*Subscriber]struct{}
// DefaultMessageHandler if no other handler for MessageType found
DefaultMessageHandler MessageHandleFunc
// Run Function on open connection by subscriper
OnOpen SubscriberEventFunc
// Run Function on close connection to subscriper
OnClose SubscriberEventFunc
// contains filtered or unexported fields
}
WebsocketEndpoint to handle Request
func NewEndpoint ¶
func NewEndpoint(log *zap.Logger) *WebsocketEndpoint
NewEndpoint - create an empty websocket
func (*WebsocketEndpoint) AddMessageHandler ¶
func (we *WebsocketEndpoint) AddMessageHandler(typ string, f MessageHandleFunc)
AddMessageHandler - add websocket message handler
func (*WebsocketEndpoint) Broadcast ¶
func (we *WebsocketEndpoint) Broadcast(msg *Message)
Broadcast Message to all subscriber (exclude sender of Message)
func (*WebsocketEndpoint) Handler ¶
func (we *WebsocketEndpoint) Handler(ctx *gin.Context)
Handler - to register in gin webservice
Click to show internal directories.
Click to hide internal directories.