Documentation
¶
Index ¶
- func WriteResponse(response http.ResponseWriter, body *JSON, statusCode int)
- type JSON
- type Middleware
- type RequestState
- type Route
- type RouteAction
- type RouteParams
- type Router
- type Server
- func (server *Server) EnableTLS(certPath string, keyPath string) error
- func (server *Server) RegisterRoute(method string, path string, middleware []Middleware, action RouteAction)
- func (server *Server) ServeHTTP(response http.ResponseWriter, request *http.Request)
- func (server *Server) Start(port int, timeout int)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func WriteResponse ¶
func WriteResponse(response http.ResponseWriter, body *JSON, statusCode int)
WriteResponse writes a JSON response back to the client
Types ¶
type Middleware ¶
type Middleware func(ctx context.Context, request *http.Request, response http.ResponseWriter, body *[]byte) (bool, int)
Middleware is a function signature for HTTP middleware that can be assigned to routes
type RequestState ¶
type RequestState struct {
// contains filtered or unexported fields
}
RequestState allows storage of miscellaneous state objects that can be referred to throughout a request
func (*RequestState) Get ¶
func (requestState *RequestState) Get(key string) interface{}
Get obtains a state value (or nil if it does not exist)
func (*RequestState) Set ¶
func (requestState *RequestState) Set(key string, value interface{})
Set stores a state value
type Route ¶
type Route struct { Path string Action RouteAction Middleware []Middleware }
Route structs define executable HTTP routes
func (*Route) MatchesPath ¶
func (route *Route) MatchesPath(path string) (bool, RouteParams)
MatchesPath checks whether the route's path matches a given path and returns any wildcard values
type RouteAction ¶
type RouteAction func(ctx context.Context, request *http.Request, response http.ResponseWriter, body *[]byte)
RouteAction is a function signature for actions carried out when a route is matched
type RouteParams ¶
RouteParams is an alias for a map to hold route wildcard parameters, where both keys and values will be strings
type Router ¶
Router represents an instance of a router
func (*Router) Dispatch ¶
func (router *Router) Dispatch(request *http.Request, response http.ResponseWriter, method string, path string, params string, body *[]byte) (bool, int, error)
Dispatch will search for and execute a route
func (*Router) RegisterRoute ¶
func (router *Router) RegisterRoute(method string, path string, middleware []Middleware, action RouteAction)
RegisterRoute stores a closure to execute against a method and path
type Server ¶
Server represents a HTTP server
func (*Server) RegisterRoute ¶
func (server *Server) RegisterRoute(method string, path string, middleware []Middleware, action RouteAction)
RegisterRoute stores a closure to execute against a method and path