Documentation ¶
Index ¶
- Constants
- Variables
- func NewNoContentError(path, method string) errors.TracerError
- type Authentication
- type Authenticator
- type Context
- func (context *Context) AddError(err qerror.FieldError)
- func (context *Context) HasError() bool
- func (context *Context) Read() ([]byte, error)
- func (context *Context) ReadObject(target interface{}) error
- func (context *Context) ReadQueryParams(target interface{}) error
- func (context *Context) SetError(err *qerror.RestError, status int)
- func (context *Context) SetResponse(model interface{}, status int) bool
- func (context *Context) Status() int
- func (context *Context) Write(s string)
- type Controller
- type NoContentError
- type RESTServer
- type RouteNode
- type Router
Constants ¶
const HealthCheckRoute = "health"
HealthCheckRoute is the default URI for health checks
const InvalidCredentialsErrorMessage = "Invalid Credentials"
InvalidCredentialsErrorMessage is returned when Credentials are invalid
Variables ¶
var ( WildCard = "*" Slash = "/" )
WildCard character for paths.
Functions ¶
func NewNoContentError ¶
func NewNoContentError(path, method string) errors.TracerError
NewNoContentError instantiates a NoContentError with a stack trace
Types ¶
type Authentication ¶ added in v1.1.0
type Authentication interface { // Type of authentication this instance provides GetKind() string // UserID that is requesting authentication GetUserID() string // GetValidity indicates whether the user id on this instance is authentic GetValidity() bool }
Authentication provides a base for authentication implementations that are used as part of the http context chain.
type Authenticator ¶ added in v1.1.0
type Authenticator interface { // Authenticate the passed context and provide the authentication and bool indicating whether the // context is authenticated Authenticate(context *Context) (Authentication, bool) // SetUserAuthentication on the passed context for the passed user ID. SetUserAuthentication(context *Context, userID string) (Authentication, bool) }
Authenticator is responsible for the initialization of a Authentication from a http context.
type Context ¶
type Context struct { context.Context URIParameters map[string]string URLParameters url.Values URI string URL *url.URL Method string Request *http.Request Response http.ResponseWriter Route *RouteNode Authentication Authentication Model interface{} Error *qerror.RestError Extended map[string]interface{} Body string // contains filtered or unexported fields }
Context serves as a structure that tracks the state of a given http Request Response chain.
func CreateContext ¶
CreateContext initializes a Context from the passed Response and Request pair, and router. The router is used for detemplating and populating the URIParameters
func (*Context) AddError ¶
func (context *Context) AddError(err qerror.FieldError)
AddError adds an error detail to the context Primary use case is to add a series of validation type errors
func (*Context) ReadObject ¶
ReadObject reads the body of the Request and unmarshals an object the same type as the passed implementation of interface{}
func (*Context) ReadQueryParams ¶
ReadQueryParams converts URL Parameters into an Object
func (*Context) SetError ¶
SetError sets the HTTP status of the response and the error to be returned
func (*Context) SetResponse ¶
SetResponse sets the HTTP status and model to be rendered in the response write Returns false if there is an Error on the context otherwise true
type Controller ¶
type Controller interface { // GetRoutes that this controller serves GetRoutes() []string Get(context *Context) Post(context *Context) Put(context *Context) Patch(context *Context) Delete(context *Context) Options(context *Context) Authenticate(context *Context) (Authentication, bool) }
Controller is the main interface for the request handlers in the Router
type NoContentError ¶
type NoContentError struct { RequestPath string RequestMethod string // contains filtered or unexported fields }
NoContentError is returned when Read is called and the Request has a 0 content length.
func (*NoContentError) Error ¶
func (err *NoContentError) Error() string
func (*NoContentError) Trace ¶
func (err *NoContentError) Trace() []string
Trace returns the stack trace for the error
type RESTServer ¶
RESTServer is a struct for managing the configuration and start up of a http/s server using the routing and controller logic in this package.
func CreateRESTServer ¶
func CreateRESTServer(address string, rootController Controller) RESTServer
CreateRESTServer initializes a RESTServer struct and returns it.
func (*RESTServer) CompleteRequest ¶
func (server *RESTServer) CompleteRequest(start time.Time, context *Context)
CompleteRequest generates output and completes the Request
func (*RESTServer) ListenAndServe ¶
func (server *RESTServer) ListenAndServe() error
ListenAndServe starts a http server listening on the address specified on the RESTServer instance.
func (*RESTServer) ListenAndServeTLS ¶
func (server *RESTServer) ListenAndServeTLS(address string, port int) error
ListenAndServeTLS starts a https server listening on the address specified on the RESTServer instance.
func (*RESTServer) ServeHTTP ¶
func (server *RESTServer) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP processes the HTTP Request
type RouteNode ¶
type RouteNode struct { // The word value assigned to this node. Value string // Any subroutes nested below this node. SubRoutes map[string]*RouteNode // The route template that was mapped to this node (if termnial). TemplateRoute string // The Controller for this node if terminal. Controller Controller }
RouteNode serves as a node in the parse tree for parsing incoming routes.
type Router ¶
type Router struct { // Routes All routes currently mapped by the router. RouteTree *RouteNode RegisteredRoutes []string }
Router is the main entry point for the Quimby ReST API server.
func CreateRouter ¶
func CreateRouter(rootController Controller) Router
CreateRouter initializes and returns a new instance of Router.
func (*Router) AddController ¶
func (router *Router) AddController(controller Controller) error
AddController adds a the passed controller on the routes returned by the controllers GetRoutes method.