Documentation ¶
Index ¶
- Constants
- func AlarmHandler(next http.Handler) http.Handler
- func GroupHandler(next http.Handler) http.Handler
- func JSONInput(req *http.Request) interface{}
- func PanicHandler(next http.Handler) http.Handler
- func PermissionHandler(next http.Handler) http.Handler
- func RoleHandler(next http.Handler) http.Handler
- func SendJSON(rw http.ResponseWriter, code int, data interface{})
- func StrokeHandler(next http.Handler) http.Handler
- type JSONError
- type JSONHandler
- type JSONResult
Constants ¶
const JSONDefaultLimit = 2048
JSONDefaultLimit is default size limit in bytes of an accepted input document.
Variables ¶
This section is empty.
Functions ¶
func AlarmHandler ¶
AlarmHandler represents a middleware that ensures the association user to alarm exists.
func GroupHandler ¶
GroupHandler defines a middleware that checks, if the group of the logged in user is a the same or a parent group of the requested object.
func PanicHandler ¶
PanicHandler middleware recovers from panic in underlying handlers and sends HTTP 500 to the client when panic happens.
func PermissionHandler ¶
PermissionHandler defines a middleware that matches the logged in user and the requested route against the role - permission - activity path for this user.
func RoleHandler ¶
RoleHandler defines a middleware that checks, if the role of the logged in user has apropriate permissions for a request and checks if the role the user wants to use has not more permissions than his/her own role.
func SendJSON ¶
func SendJSON(rw http.ResponseWriter, code int, data interface{})
SendJSON sends data JSON encoded to the response writer with a given HTTP status code.
Types ¶
type JSONError ¶
type JSONError struct { // Code is the HTTP status code of the result defaults // to http.StatusInternalServerError if not set. Code int // The message of the error. Message string }
JSONError is an error if returned by the JSONHandler.Handle function which ends up encoded as a JSON document.
type JSONHandler ¶
type JSONHandler struct { // Input (if not nil) is called to fill a data structure // returned by this function. Input func(*http.Request) interface{} // Authorized checks if the predicates are fullfilled to call the Handle // function. If not http.StatusUnauthorized is send back. Authorized func(*http.Request) bool // Handle is called to handle the incoming HTTP request. // in is the data structure returned by Input. Its nil if Input is nil. Handle func(rep *http.Request) (JSONResult, error) // Limit overides the default size of accepted input documents. // Set to a negative value to allow an arbitrary size. // Handle with care! Limit int64 }
JSONHandler implements a middleware to ease the handing JSON input streams and return JSON documents as output.
func (*JSONHandler) ChainAuthorize ¶
func (j *JSONHandler) ChainAuthorize(fn func(*http.Request) bool)
func (*JSONHandler) ServeHTTP ¶
func (j *JSONHandler) ServeHTTP(rw http.ResponseWriter, req *http.Request)
ServeHTTP makes the JSONHandler a middleware.
type JSONResult ¶
type JSONResult struct { // Code is the HTTP status code to be set which defaults to http.StatusOK (200). Code int // Result is serialized to JSON. // If the type is an io.Reader its copied through. Result interface{} }
JSONResult defines the return type of JSONHandler handler function.