Documentation ¶
Overview ¶
Package rest contains the functions that make it easier to manager api handler functions
Index ¶
- Constants
- func ERROR(w http.ResponseWriter, err error)
- func JSON(w http.ResponseWriter, statusCode int, data interface{})
- func RecoverFromPanic(w http.ResponseWriter)
- func UnmarshalERROR(body io.Reader) error
- type CRUDHandler
- type Handler
- func (h Handler) Delete() Handler
- func (h Handler) Get() Handler
- func (h Handler) HTTPHandlerFunc() http.HandlerFunc
- func (h Handler) JSON() Handler
- func (h Handler) Methods(methods ...string) http.HandlerFunc
- func (h Handler) Post() Handler
- func (h Handler) Put() Handler
- func (h Handler) Recover() Handler
- func (h Handler) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (h Handler) Validate(auth auth.Auth) Handler
Constants ¶
const ( // HeaderScopeKey is used to obtain or to change the scope in the http // request header, usually used in the handlers of the api package and the // client of the controller package. HeaderScopeKey = "Scope" )
Variables ¶
This section is empty.
Functions ¶
func ERROR ¶
func ERROR(w http.ResponseWriter, err error)
ERROR reports the error back to the user within a JSON format
func JSON ¶
func JSON(w http.ResponseWriter, statusCode int, data interface{})
JSON writes the data into the response writer with a JSON format
func RecoverFromPanic ¶
func RecoverFromPanic(w http.ResponseWriter)
RecoverFromPanic will handle panic
func UnmarshalERROR ¶
UnmarshalERROR generates a golang error with the response body created by the ERROR function
Types ¶
type CRUDHandler ¶
type CRUDHandler interface { HandleCreate() Handler HandleDelete() Handler HandleUpdate() Handler HandleGet() Handler GetAuth() auth.Auth }
CRUDHandler handles crud requests to a given resource
type Handler ¶
type Handler func(w http.ResponseWriter, r *http.Request)
Handler is an alias of the api router function. It acts as the function that handles the routes but at the same time it contains certain methods attached to it that allows for more utility. For an example check the JSON function.
func HandleCRUD ¶
func HandleCRUD(handler CRUDHandler) Handler
HandleCRUD uses a CRUDHandler to handle HTTP requests for a CRUD resource
func (Handler) HTTPHandlerFunc ¶
func (h Handler) HTTPHandlerFunc() http.HandlerFunc
HTTPHandlerFunc transforms the rest.handler to a http.handlerFunc type
func (Handler) Methods ¶
func (h Handler) Methods(methods ...string) http.HandlerFunc
Methods allows for generic method definition