server

package
v0.0.0-...-2187358 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 30, 2022 License: MIT Imports: 9 Imported by: 0

Documentation

Index

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:

  1. If a url's prefix or pattern matches a socket.io request pattern ("/socker.io/...") then the socketRequestHandler is relayed the request altogether.
  2. 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.
  3. If a url matches a room request regex pattern ("/v/..."), then the room index file is served back to the client.
  4. If a url begins with an api request prefix ("/api/..."), then the api handler is relayed the request entirely.
  5. 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

type ServerOptions struct {
	Host string
	Out  io.Writer
	Port string

	Server *http.Server
}

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.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL