Documentation ¶
Index ¶
- Variables
- func ExtractParams(template, path string) (map[string]interface{}, error)
- func MatchRoute(pattern, path string) bool
- type Channel
- type Client
- type Config
- type Context
- type ExtractKeyFunc
- type Hub
- func (h *Hub) ClientsCount(id string) int
- func (h *Hub) Count() int
- func (h *Hub) EnsureClean()
- func (h *Hub) GetChannel(id string) *Channel
- func (h *Hub) Send(channel string, data interface{}) error
- func (h *Hub) Subscribe(id string, session *melody.Session) *Channel
- func (h *Hub) UnSubscribe(id string, session *melody.Session)
- type Luna
- type OnMessageHandler
- type Route
- type WsMessage
Constants ¶
This section is empty.
Variables ¶
var ( COMMAND_SUBSCRIBE = "subscribe" COMMAND_MESSAGE = "message" COMMAND_UNSUBSCRIBE = "unsubscribe" )
var DefaultConfig = &Config{BufferSize: 512 * 10, MaxMessageSize: 512 * 10}
Functions ¶
func ExtractParams ¶
ExtractParams extracts data from path parameter.
func MatchRoute ¶
MatchRoute checks if path matches the patten supplied. E.g pattern=/rooms/{id}/messages will match path=/rooms/12/messages
Types ¶
type Channel ¶
A message channel. Multiple clients can subscribe to a channel, message will be broadcast to all clients anytime Channel.Send(data) is called
func (*Channel) Send ¶
Send broadcast message to all connected clients and update their last activity time
func (*Channel) UnSubscribe ¶
UnSubscribe removes a session from a channel
type Config ¶
type Config struct { BufferSize int MaxMessageSize int64 KeyExtractor ExtractKeyFunc }
Config holds luna configurations
type ExtractKeyFunc ¶
ExtractKeyFunc to assign a unique key for each session can be used like :-
keyFunc := func(r *http.Request) string { return r.Header.Get("x-auth-token") }
type Hub ¶
type Hub struct {
Channels []*Channel //Slice of channels in this Hub
}
Hub holds all channels in a slice. Clients can subscribe and send message to channels through the Hub
func (*Hub) ClientsCount ¶
ClientsCount returns no of connected clients in a channel
func (*Hub) EnsureClean ¶
func (h *Hub) EnsureClean()
EnsureClean keep clients slice clean. Remove all clients that has been idle for more than 10minutes
func (*Hub) GetChannel ¶
GetChannel returns a Channel identified by @param id
func (*Hub) Send ¶
Send sends data payload to a channel. This broadcast @params data to all connected clients
type Luna ¶
type Luna struct {
// contains filtered or unexported fields
}
func (*Luna) Handle ¶
func (l *Luna) Handle(path string, f OnMessageHandler)
Handle registers a new Route
func (*Luna) HandleHttpRequest ¶
type OnMessageHandler ¶
type OnMessageHandler func(context *Context)
type Route ¶
type Route struct { Path string OnNewMessage OnMessageHandler }