Documentation ¶
Overview ¶
Package app provides application support for context and MongoDB access. Current Status Codes:
200 OK : StatusOK : Call is success and returning data. 204 No Content : StatusNoContent : Call is success and returns no data. 400 Bad Request : StatusBadRequest : Invalid post data (syntax or semantics). 401 Unauthorized : StatusUnauthorized : Authentication failure. 404 Not Found : StatusNotFound : Invalid URL or identifier. 500 Internal : StatusInternalServerError : Application specific beyond scope of user.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNotFound is abstracting the mgo not found error. ErrNotFound = errors.New("No user(s) found") // ErrInvalidID occurs when an ID is not in a valid form. ErrInvalidID = errors.New("ID is not in it's proper form") // ErrValidation occurs when there are validation errors. ErrValidation = errors.New("Validation errors occurred") )
Functions ¶
func GetSession ¶
func GetSession() *mgo.Session
GetSession returns a copy of the master session for use.
Types ¶
type App ¶
type App struct { *httptreemux.TreeMux // contains filtered or unexported fields }
App is the entrypoint into our application and what configures our context object for each of our http handlers. Feel free to add any configuration data/logic on this App struct
func New ¶
func New(mw ...Middleware) *App
New create an App value that handle a set of routes for the application. You can provide any number of middleware and they'll be used to wrap every request handler.
type Context ¶
type Context struct { Session *mgo.Session http.ResponseWriter Request *http.Request Params map[string]string SessionID string Status int }
Context contains data associated with a single request.
func (*Context) Respond ¶
Respond sends JSON to the client. If code is StatusNoContent, v is expected to be nil.
func (*Context) RespondError ¶
RespondError sends JSON describing the error
func (*Context) RespondInvalid ¶
RespondInvalid sends JSON describing field validation errors.
type Handler ¶
A Handler is a type that handles an http request within our own little mini framework. The fun part is that our context is fully controlled and configured by us so we can extend the functionality of the Context whenever we want.
type Middleware ¶
A Middleware is a type that wraps a handler to remove boilerplate or other concerns not direct to any given Handler.