Documentation ¶
Index ¶
- Constants
- Variables
- func Add(endpoint string, controller ControllerType, function string, persist bool)
- func CreateDefaultResponse(req *Request) ([]byte, error)
- func InSlice(str string, items []string) bool
- func NewOffset(x float64, y float64, z float64) (*offset, error)
- func NewPayload(sessionToken string, offset *offset, params map[string]interface{}) (payload, error)
- func NewResponse(sessionToken string, endpoint string, payload payload) (*messageData, error)
- func Run() error
- type AppController
- type Broadcast
- type Broadcaster
- type CachedControllersList
- func (ccl *CachedControllersList) Add(key string, ac *AppController)
- func (ccl *CachedControllersList) DeleteOldest() error
- func (ccl *CachedControllersList) Exists(key string) bool
- func (ccl *CachedControllersList) Get(key string) (*AppController, error)
- func (ccl *CachedControllersList) IsEmpty() bool
- func (ccl *CachedControllersList) Length() int
- type CarrotTransformController
- type Client
- type Clients
- type ControllerType
- type DefaultRouter
- type DefaultSessionStore
- func (s *DefaultSessionStore) Delete(token SessionToken) error
- func (s *DefaultSessionStore) Exists(token SessionToken) bool
- func (s *DefaultSessionStore) Get(token SessionToken) (*Session, error)
- func (s *DefaultSessionStore) GetPrimaryDeviceToken() (SessionToken, error)
- func (s *DefaultSessionStore) Length() int
- func (s *DefaultSessionStore) NewSession() (SessionToken, *Session, error)
- func (s *DefaultSessionStore) Range(f func(key, value interface{}) bool)
- type Dispatcher
- type Endpoint
- type MiddlewarePipeline
- type OutMessage
- type PriorityQueue
- type Request
- type ResponseParams
- type Route
- type Router
- type RoutingTable
- type Server
- type Session
- type SessionStore
- type SessionToken
Constants ¶
const ( MetricCount = 12 RequestCreation = iota // 1 MiddlewareInput // 2 MiddlewareOutputToDispatcher // 3 DispatchLookupStart // 4 DispatchLookupEnd // 5 DispatchRequestStart // 6 DispatchRequestEnd // 7 MethodReflectionStart // 8 MethodReflectionEnd // 9 ControllerMethodStart // 10 ControllerMethodEnd // 11 ResponderInvocation ResponderElapsed )
const (
InputChannelSize = 16384
)
Variables ¶
var Environment string
Functions ¶
func CreateDefaultResponse ¶
CreateDefaultResponse generates a JSON object (ready to broadcast response) from a request in one step. This function offers brevity but does not support extra input from controllers (skips adding params).
func NewOffset ¶
NewOffset instantiates a struct to hold coordinate data used later to create JSON objects.
func NewPayload ¶
func NewPayload(sessionToken string, offset *offset, params map[string]interface{}) (payload, error)
NewPayload instantiates a struct to hold offset and params data used later to create JSON objects.
func NewResponse ¶
NewResponse instantiates a struct that will be directly converted to a JSON object to be broadcasted to devices.
Types ¶
type AppController ¶
type AppController struct { Controller ControllerType // contains filtered or unexported fields }
func NewController ¶
func NewController(c interface{}, isStream bool) (*AppController, error)
NewController initializes a new controller instance of controllerType.
func (*AppController) Invoke ¶
func (c *AppController) Invoke(route *Route, req *Request) error
Invoke reflects on the controller to find the correct function to call and then calls it.
func (*AppController) Persist ¶
func (c *AppController) Persist(p bool)
type Broadcast ¶
type Broadcast struct {
// contains filtered or unexported fields
}
Response groups are enumerated by the constants in this file. To add a new response group, add it to the list of constants at the start of the file.
func NewBroadcast ¶
func NewBroadcast(broadcaster Broadcaster) *Broadcast
NewBroadcast initializes a new instance of the Broadcast struct.
type Broadcaster ¶
type Broadcaster struct {
// contains filtered or unexported fields
}
manage broadcast groups with the broadcaster
func NewBroadcaster ¶
func NewBroadcaster(pool *Clients) Broadcaster
NewBroadcaster initializes a new instance of the Broadcaster struct.
func (*Broadcaster) Run ¶
func (br *Broadcaster) Run()
Run sends buffered responses to devices, deletes expired device connections, and logs information.
type CachedControllersList ¶
type CachedControllersList struct {
// contains filtered or unexported fields
}
func NewCachedControllersList ¶
func NewCachedControllersList() *CachedControllersList
NewCachedControllersList initializes a new instance of the CachedControllersList struct.
func (*CachedControllersList) Add ¶
func (ccl *CachedControllersList) Add(key string, ac *AppController)
Add maintains the existence of a new controller so that it does not have to be created again upon request reference.
func (*CachedControllersList) DeleteOldest ¶
func (ccl *CachedControllersList) DeleteOldest() error
DeleteOldest frees the memory of the oldest controller maintained by the cache.
func (*CachedControllersList) Exists ¶
func (ccl *CachedControllersList) Exists(key string) bool
Exists checks whether a controller of the given type is already being cached.
func (*CachedControllersList) Get ¶
func (ccl *CachedControllersList) Get(key string) (*AppController, error)
Get returns a reference to the controller whose type matches the key.
func (*CachedControllersList) IsEmpty ¶
func (ccl *CachedControllersList) IsEmpty() bool
IsEmpty determines whether the cache is currently maintaining any controllers.
func (*CachedControllersList) Length ¶
func (ccl *CachedControllersList) Length() int
Length returns the size of the cache: the number of maintained controllers.
type CarrotTransformController ¶
type CarrotTransformController struct {
// contains filtered or unexported fields
}
internal controller used to update transforms of primary and secondary devices
func (*CarrotTransformController) Transform ¶
func (c *CarrotTransformController) Transform(req *Request, broadcast *Broadcast)
Transform gathers and stores device locations via movement vectors in order to perform later calculations.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
func (*Client) IsRecipient ¶
type Clients ¶
type Clients struct {
// contains filtered or unexported fields
}
func NewClientList ¶
type ControllerType ¶
type ControllerType interface{}
type DefaultRouter ¶
type DefaultRouter struct {
// contains filtered or unexported fields
}
func (*DefaultRouter) Length ¶
func (r *DefaultRouter) Length() int
func (*DefaultRouter) Range ¶
func (r *DefaultRouter) Range(f func(key, value interface{}) bool)
type DefaultSessionStore ¶
type DefaultSessionStore struct {
// contains filtered or unexported fields
}
func (*DefaultSessionStore) Delete ¶
func (s *DefaultSessionStore) Delete(token SessionToken) error
Deletes a session and updates the session count variable
func (*DefaultSessionStore) Exists ¶
func (s *DefaultSessionStore) Exists(token SessionToken) bool
Determines whether a given session exists based on the SessionToken provided
func (*DefaultSessionStore) Get ¶
func (s *DefaultSessionStore) Get(token SessionToken) (*Session, error)
Retrieves a session based on its SessionToken
Get() does not guarantee that a connection is open this must be checked with the expired() function once the session is retrieved
func (*DefaultSessionStore) GetPrimaryDeviceToken ¶
func (s *DefaultSessionStore) GetPrimaryDeviceToken() (SessionToken, error)
Retrieves the SessionToken of the primary device and returns an error if no primary device exists
func (*DefaultSessionStore) Length ¶
func (s *DefaultSessionStore) Length() int
Returns the number of sessions currently existing including inactive sessions
func (*DefaultSessionStore) NewSession ¶
func (s *DefaultSessionStore) NewSession() (SessionToken, *Session, error)
Creates a new session and adds it to the SessionStore. Returns the generated, UUID, a pointer to the Session object, and an error
func (*DefaultSessionStore) Range ¶
func (s *DefaultSessionStore) Range(f func(key, value interface{}) bool)
Provided a function, Range() iterates over every session in a thread-safe manner and applies that function to the session. If the function provided as an argument returns true after acting on the session, iteration continues. Otherwise, the range() function breaks
type Dispatcher ¶
type Dispatcher struct {
// contains filtered or unexported fields
}
func NewDispatcher ¶
func NewDispatcher() *Dispatcher
NewDispatcher initializes a new instance of the Dispatcher struct.
func (*Dispatcher) Run ¶
func (dp *Dispatcher) Run()
Run establishes request routes, dispatches requests, and logs information.
type MiddlewarePipeline ¶
type MiddlewarePipeline struct { In chan *Request // contains filtered or unexported fields }
func NewMiddlewarePipeline ¶
func NewMiddlewarePipeline() *MiddlewarePipeline
func (*MiddlewarePipeline) Run ¶
func (mw *MiddlewarePipeline) Run()
type OutMessage ¶
type OutMessage struct {
// contains filtered or unexported fields
}
func OutboundMessage ¶
func OutboundMessage(message []byte, sessions []string) OutMessage
OutboundMessage initializes a new instance of the OutMessage struct.
type PriorityQueue ¶
type PriorityQueue struct {
// contains filtered or unexported fields
}
PriorityQueue represents the queue
func NewPriorityQueue ¶
func NewPriorityQueue() *PriorityQueue
New initializes an empty priority queue.
func (*PriorityQueue) Insert ¶
func (p *PriorityQueue) Insert(v interface{}, priority float64)
Insert inserts a new element into the queue. No action is performed on duplicate elements.
func (*PriorityQueue) Len ¶
func (p *PriorityQueue) Len() int
Len returns the number of elements in the queue.
func (*PriorityQueue) Pop ¶
func (p *PriorityQueue) Pop() (interface{}, error)
Pop removes the element with the highest priority from the queue and returns it. In case of an empty queue, an error is returned.
func (*PriorityQueue) UpdatePriority ¶
func (p *PriorityQueue) UpdatePriority(x interface{}, newPriority float64)
UpdatePriority changes the priority of a given item. If the specified item is not present in the queue, no action is performed.
type Request ¶
type Request struct { SessionToken SessionToken Params map[string]interface{} Offset *offset // contains filtered or unexported fields }
func NewRequest ¶
type ResponseParams ¶
type ResponseParams map[string]interface{}
for use of controller-level control
type Route ¶
type Route struct {
// contains filtered or unexported fields
}
func (*Route) Controller ¶
func (r *Route) Controller() ControllerType
type RoutingTable ¶
type Server ¶
type Server struct { //keep track of middleware Middleware *MiddlewarePipeline // contains filtered or unexported fields }
the server maintains the list of clients and broadcasts messages to the clients
func NewServer ¶
func NewServer(sessionStore SessionStore) (*Server, error)
type Session ¶
type Session struct { Token SessionToken T_L *offset T_P *offset // contains filtered or unexported fields }
Potentially will need to be a sync Map
type SessionStore ¶
type SessionStore interface { NewSession() (SessionToken, *Session, error) Exists(SessionToken) bool Get(SessionToken) (*Session, error) GetPrimaryDeviceToken() (SessionToken, error) Range(func(key, value interface{}) bool) Delete(SessionToken) error Length() int }
func NewDefaultSessionManager ¶
func NewDefaultSessionManager() SessionStore
Provides a pointer to a singleton of the SessionStore interface for use in Carrot modules
type SessionToken ¶
type SessionToken string