Documentation ¶
Index ¶
- Constants
- func Prettify(obj interface{}) string
- type Context
- type Error
- type JSON
- type Logger
- type LoggingSubscriptionManager
- type Message
- type Method
- type Object
- type RPC
- type RPCHandler
- type RPCs
- type Resource
- type ResourceHandler
- type Resources
- type Router
- func (self *Router) CheckPrincipal(r *http.Request) (principal string, ok bool)
- func (self *Router) Debugf(format string, args ...interface{})
- func (self *Router) DefaultOnConnect(ws *websocket.Conn, principal string)
- func (self *Router) DefaultOnDisconnectFactory(ws *websocket.Conn, principal string) func()
- func (self *Router) DeliverError(ws *websocket.Conn, cause interface{}, err error)
- func (self *Router) Errorf(format string, args ...interface{})
- func (self *Router) Fatalf(format string, args ...interface{})
- func (self *Router) HandleRPCMessage(c Context) (err error)
- func (self *Router) HandleResourceMessage(c Context) (err error)
- func (self *Router) Infof(format string, args ...interface{})
- func (self *Router) IsSubscribing(principal, uri string, timeout time.Duration) (result bool)
- func (self *Router) Logf(level int, format string, args ...interface{})
- func (self *Router) MarkActive(principal string)
- func (self *Router) ProcessMessages(ws *websocket.Conn, principal string, handlerFunc func(*Message) error)
- func (self *Router) RPC(method string, handler RPCHandler) (result *RPC)
- func (self *Router) RemoveSubscriber(principal, uri string)
- func (self *Router) Resource(exp string) (result *Resource)
- func (self *Router) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (self *Router) SetupConnection(ws *websocket.Conn) (principal string, ok bool)
- func (self *Router) Tracef(format string, args ...interface{})
- func (self *Router) Upgrader() *websocket.Upgrader
- type SubscriptionManager
- type Token
Constants ¶
const ( SubscribeType = "Subscribe" UnsubscribeType = "Unsubscribe" UpdateType = "Update" CreateType = "Create" DeleteType = "Delete" RPCType = "RPC" ErrorType = "Error" )
const ( FatalLevel = iota ErrorLevel InfoLevel DebugLevel TraceLevel )
const (
FetchType = "Fetch"
)
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Context ¶
type Context interface { Logger Conn() *websocket.Conn Message() *Message Principal() string Match() []string SetMatch([]string) Data() JSON SetData(JSON) IsSubscribing(principal, uri string, timeout time.Duration) bool }
Context describes a single WebSocket message and its environment
func NewContext ¶
type JSON ¶
type JSON struct {
Data interface{}
}
JSON wraps anything that is a JSON object.
func (JSON) GetStringSlice ¶
GetStringSLice returns the value under key as a string slice.
type Logger ¶
type Logger interface { Fatalf(format string, params ...interface{}) Errorf(format string, params ...interface{}) Infof(format string, params ...interface{}) Debugf(format string, params ...interface{}) Tracef(format string, params ...interface{}) }
Loggers be loggin'
type LoggingSubscriptionManager ¶
type LoggingSubscriptionManager interface { SubscriptionManager Logger }
LoggingSubscriptionManager logs and manages subscriptions...
type Message ¶
type Message struct { Type string Object *Object `json:",omitempty"` Method *Method `json:",omitempty"` Error *Error `json:",omitempty"` }
Message wraps Objects in JSON messages.
type Object ¶
type Object struct { URI string Data interface{} `json:",omitempty"` }
Object is used to send JSON messages to subscribing WebSockets.
type RPC ¶
type RPC struct { Method string Handler RPCHandler Authenticated bool }
RPC describes how the router ought to treat incoming requests for a given RPC method
type RPCHandler ¶
RPCHandlers handle RPC requests
type Resource ¶
type Resource struct { Path *regexp.Regexp Handlers map[string]ResourceHandler Authenticated map[string]bool // contains filtered or unexported fields }
Resource describes how the router ought to treat incoming requests for a resource found under a given URI regexp
type ResourceHandler ¶
ResourceHandler will handle a message regarding an operation on a resource
type Router ¶
type Router struct { Resources Resources RPCs RPCs Logger *log.Logger LogLevel int OnDisconnectFactory func(ws *websocket.Conn, principal string) func() OnConnect func(ws *websocket.Conn, principal string) DevMode bool Secret string // contains filtered or unexported fields }
Router controls incoming WebSocket messages
func (*Router) CheckPrincipal ¶
func (*Router) DefaultOnConnect ¶
DefaultOnConnect will just log the incoming connection
func (*Router) DefaultOnDisconnectFactory ¶
DefaultOnDisconnectFactory will return functions that just log the disconnecting connection
func (*Router) DeliverError ¶
DeliverError sends an error message along the provided WebSocket connection
func (*Router) HandleRPCMessage ¶
HandleRPCMessage will handle the message that produced c, by finding a matching RPC method (if there is one) and sending it the context.
func (*Router) HandleResourceMessage ¶
HandleResourceMessage will handle the message that produced c, by finding a matching resource (if there is one) and sending it the context.
func (*Router) IsSubscribing ¶
IsSubscriber returns true if principal is currently subscribing to uri.
func (*Router) Logf ¶
Logf will log the format and args if level is less than the LogLevel of this Router
func (*Router) MarkActive ¶
MarkActive will timestamp the principal as active, for purposes of checking whether the principal is subscribing.
func (*Router) ProcessMessages ¶
func (self *Router) ProcessMessages(ws *websocket.Conn, principal string, handlerFunc func(*Message) error)
ProcessMessages will decode messages from the ws, and handle them with handlerFunc
func (*Router) RPC ¶
func (self *Router) RPC(method string, handler RPCHandler) (result *RPC)
RPC creates an RPC method receiving messages matching the provided method name
func (*Router) RemoveSubscriber ¶
RemoveSubscriber will remember that principal stopped subscribing to uri
func (*Router) Resource ¶
Resource creates a resource receiving messages matching the provided regexp
func (*Router) ServeHTTP ¶
func (self *Router) ServeHTTP(w http.ResponseWriter, r *http.Request)
Implements http.Handler
func (*Router) SetupConnection ¶
SetupConnection will try to find a principal for the provided connection, log it, and return if it's ok to continue processing it.
type SubscriptionManager ¶
type SubscriptionManager interface {
IsSubscribing(principal, uri string, timeout time.Duration) bool
}
SubscriptionManager be managin' subscriptions