Documentation ¶
Overview ¶
Package nova is an HTTP request multiplexer. It matches the URL of each incoming request against a list of registered patterns and calls the handler for the pattern that most closely matches the URL. As well as providing some nice logging and response features.
Index ¶
- type ErrorFunc
- type JSONError
- type JSONErrors
- type Middleware
- type Node
- type Request
- func (r *Request) Error(statusCode int, msg string, userErr error) error
- func (r *Request) GetMethod() string
- func (r *Request) Header() http.Header
- func (r *Request) JSON(code int, obj interface{}) error
- func (r *Request) QueryParam(key string) string
- func (r *Request) ReadJSON(i interface{}) error
- func (r *Request) RouteParam(key string) string
- func (r *Request) Send(data interface{}) error
- func (r *Request) StatusCode(c int)
- func (r *Request) Write(code int, data interface{}) error
- func (r *Request) WriteHeader(c int)
- type RequestFunc
- type Route
- type RouteGroup
- func (r *RouteGroup) All(route string, routeFunc RequestFunc)
- func (r *RouteGroup) Delete(route string, routeFunc RequestFunc)
- func (r *RouteGroup) Get(route string, routeFunc RequestFunc)
- func (r *RouteGroup) Post(route string, routeFunc RequestFunc)
- func (r *RouteGroup) Put(route string, routeFunc RequestFunc)
- func (r *RouteGroup) Restricted(method, route string, routeFunc RequestFunc)
- type Server
- func (sn *Server) All(route string, routeFunc RequestFunc)
- func (sn *Server) Delete(route string, routeFunc RequestFunc)
- func (sn *Server) EnableDebug(debug bool)
- func (sn *Server) ErrorFunc(f ErrorFunc)
- func (sn *Server) Get(route string, routeFunc RequestFunc)
- func (sn *Server) Group(path string) *RouteGroup
- func (sn *Server) Post(route string, routeFunc RequestFunc)
- func (sn *Server) Put(route string, routeFunc RequestFunc)
- func (sn *Server) Restricted(method, route string, routeFunc RequestFunc)
- func (sn *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (sn *Server) Use(f func(req *Request, next func()))
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type JSONError ¶
type JSONError struct { Code int `json:"code"` Errors []string `json:"errors"` Message string `json:"message"` }
JSONError resembles the RESTful standard for an error response
type JSONErrors ¶
type JSONErrors struct {
Error JSONError `json:"error"`
}
JSONErrors holds the JSONError response
type Middleware ¶
type Middleware struct {
// contains filtered or unexported fields
}
Middleware holds all middleware functions
type Node ¶
type Node struct {
// contains filtered or unexported fields
}
Node holds a single route with accompanying children routes
type Request ¶
type Request struct { *http.Request ResponseWriter http.ResponseWriter BaseUrl string ResponseCode int // contains filtered or unexported fields }
Request resembles an incoming request
func NewRequest ¶
func NewRequest(w http.ResponseWriter, r *http.Request) *Request
NewRequest creates a new Request pointer for an incoming request
func (*Request) GetMethod ¶
GetMethod provides a simple way to return the request method type as a string
func (*Request) Header ¶
Header returns the header map that will be sent by WriteHeader. The Header map also is the mechanism with which Handlers can set HTTP trailers.
Changing the header map after a call to WriteHeader (or Write) has no effect unless the modified headers are trailers.
There are two ways to set Trailers. The preferred way is to predeclare in the headers which trailers you will later send by setting the "Trailer" header to the names of the trailer keys which will come later. In this case, those keys of the Header map are treated as if they were trailers. See the example. The second way, for trailer keys not known to the Handler until after the first Write, is to prefix the Header map keys with the TrailerPrefix constant value. See TrailerPrefix.
To suppress automatic response headers (such as "Date"), set their value to nil.
func (*Request) QueryParam ¶
QueryParam checks for and returns param or "" if doesn't exist
func (*Request) RouteParam ¶
RouteParam checks for and returns param or "" if doesn't exist
func (*Request) StatusCode ¶
StatusCode sets the status code header
func (*Request) WriteHeader ¶
WriteHeader sends an HTTP response header with the provided status code.
If WriteHeader is not called explicitly, the first call to Write will trigger an implicit WriteHeader(http.StatusOK). Thus explicit calls to WriteHeader are mainly used to send error codes.
The provided code must be a valid HTTP 1xx-5xx status code. Only one header may be written. Go does not currently support sending user-defined 1xx informational headers, with the exception of 100-continue response header that the Server sends automatically when the Request.Body is read.
type RequestFunc ¶
RequestFunc is the callback used in all handler func
type Route ¶
type Route struct {
// contains filtered or unexported fields
}
Route is the construct of a single route pattern
type RouteGroup ¶
type RouteGroup struct {
// contains filtered or unexported fields
}
RouteGroup is used to add routes prepending a base path
func (*RouteGroup) All ¶
func (r *RouteGroup) All(route string, routeFunc RequestFunc)
All adds route for all http methods
func (*RouteGroup) Delete ¶
func (r *RouteGroup) Delete(route string, routeFunc RequestFunc)
Delete adds only DELETE method to route
func (*RouteGroup) Get ¶
func (r *RouteGroup) Get(route string, routeFunc RequestFunc)
Get adds only GET method to route
func (*RouteGroup) Post ¶
func (r *RouteGroup) Post(route string, routeFunc RequestFunc)
Post adds only POST method to route
func (*RouteGroup) Put ¶
func (r *RouteGroup) Put(route string, routeFunc RequestFunc)
Put adds only PUT method to route
func (*RouteGroup) Restricted ¶
func (r *RouteGroup) Restricted(method, route string, routeFunc RequestFunc)
Restricted adds route that is restricted by method
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server represents the router and all associated data
func (*Server) All ¶
func (sn *Server) All(route string, routeFunc RequestFunc)
All adds route for all http methods
func (*Server) Delete ¶
func (sn *Server) Delete(route string, routeFunc RequestFunc)
Delete adds only DELETE method to route
func (*Server) EnableDebug ¶
EnableDebug toggles output for incoming requests
func (*Server) Get ¶
func (sn *Server) Get(route string, routeFunc RequestFunc)
Get adds only GET method to route
func (*Server) Group ¶
func (sn *Server) Group(path string) *RouteGroup
Group creates a new sub router that appends the path prefix
func (*Server) Post ¶
func (sn *Server) Post(route string, routeFunc RequestFunc)
Post adds only POST method to route
func (*Server) Put ¶
func (sn *Server) Put(route string, routeFunc RequestFunc)
Put adds only PUT method to route
func (*Server) Restricted ¶
func (sn *Server) Restricted(method, route string, routeFunc RequestFunc)
Restricted adds route that is restricted by method