Documentation ¶
Overview ¶
Package rest contains the functions that make it easier to manager api handler functions
Index ¶
- Constants
- func AttachProfiler(m *http.ServeMux)
- func ERROR(w http.ResponseWriter, err error)
- func JSON(w http.ResponseWriter, statusCode int, data interface{})
- func RecoverFromPanic(w http.ResponseWriter, execOnRecover ...func())
- 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(execOnRecover ...func()) 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 AttachProfiler ¶ added in v0.1.3
AttachProfiler is responsible for adding the pprof routes to the server mux passed as a parameter
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, execOnRecover ...func())
RecoverFromPanic will handle panic
func UnmarshalERROR ¶
UnmarshalERROR generates an ierror error with the response body created by the ERROR function.
Note that this function will always return an error no matter if it found the error on the body or not, that means that if the error details cannot be found on the body of the response body it will generate a unkown error
Types ¶
type CRUDHandler ¶
type CRUDHandler interface { HandleCreate() Handler HandleDelete() Handler HandleUpdate() Handler HandleGet() Handler GetAuth() auth.Auth GetCancel() func() }
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