Documentation ¶
Index ¶
- type RequestHandler
- func (h *RequestHandler) HandleFile(url string, w http.ResponseWriter, r *http.Request)
- func (h *RequestHandler) HandlePath(url string, w http.ResponseWriter, r *http.Request)
- func (h *RequestHandler) HandleRoom(url string, w http.ResponseWriter, r *http.Request)
- func (h *RequestHandler) HandleStream(url string, w http.ResponseWriter, r *http.Request)
- func (h *RequestHandler) RegisterPath(p path.Path)
- func (h *RequestHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
- type RequestRouter
- type ServerOptions
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type RequestHandler ¶
type RequestHandler struct {
// contains filtered or unexported fields
}
RequestHandler implements http.Handler and provides additional websocket request handling. It also stores generic path handlers for request not matching a specific set of criteria.
func NewRequestHandler ¶
func NewRequestHandler(socketRequestHandler *socket.Handler, connHandler connection.ConnectionHandler) *RequestHandler
func (*RequestHandler) HandleFile ¶
func (h *RequestHandler) HandleFile(url string, w http.ResponseWriter, r *http.Request)
func (*RequestHandler) HandlePath ¶
func (h *RequestHandler) HandlePath(url string, w http.ResponseWriter, r *http.Request)
Handle performs a path-url lookup. If a path by a given url has not been registered, a boolean false is returned. If an error occurs while handling a path, a boolean true is returned, as the path exists, and the error is returned.
func (*RequestHandler) HandleRoom ¶
func (h *RequestHandler) HandleRoom(url string, w http.ResponseWriter, r *http.Request)
func (*RequestHandler) HandleStream ¶
func (h *RequestHandler) HandleStream(url string, w http.ResponseWriter, r *http.Request)
func (*RequestHandler) RegisterPath ¶
func (h *RequestHandler) RegisterPath(p path.Path)
func (*RequestHandler) ServeHTTP ¶
func (h *RequestHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP handles incoming http requests. A request is handled based on its url string. The following steps are taken when evaluating a request's url:
- If a url's prefix or pattern matches a socket.io request pattern ("/socker.io/...") then the socketRequestHandler is relayed the request altogether.
- If a socketRequestHandler has not been defined, or the url matches a file-root location pattern ("/src/static/...") then it is served as a static file.
- If a url matches a room request regex pattern ("/v/..."), then the room index file is served back to the client.
- If a url begins with an api request prefix ("/api/..."), then the api handler is relayed the request entirely.
- If a url does not match any of the above patterns, it is then treated as a generic "path", which requires a path-handler for that specific url to have been registered.
type RequestRouter ¶
type RequestRouter struct {
// contains filtered or unexported fields
}
func NewRequestRouter ¶
func NewRequestRouter() *RequestRouter
func (*RequestRouter) AddRoute ¶
func (r *RequestRouter) AddRoute(from, to string)
func (*RequestRouter) Route ¶
func (r *RequestRouter) Route(url string) string
Route receives a request url string and returns the mapped value (if one exists), or the url string
type ServerOptions ¶
func NewServer ¶
func NewServer(requestHandler *RequestHandler, opts *ServerOptions) *ServerOptions
New creates a new server from server options and ensures that at least a host and a port have been set.
func (*ServerOptions) Serve ¶
func (s *ServerOptions) Serve()
Serve starts an http server using specified settings.