v1.0.1 Latest Latest

This package is not in the latest version of its module.

Go to latest
Published: Apr 1, 2020 License: Apache-2.0 Imports: 17 Imported by: 0




View Source
const JSONDefaultLimit = 2048

JSONDefaultLimit is default size limit in bytes of an accepted input document.


This section is empty.


func AlarmHandler

func AlarmHandler(next http.Handler) http.Handler

AlarmHandler represents a middleware that ensures the association user to alarm exists.

func GroupHandler

func GroupHandler(next http.Handler) http.Handler

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 JSONInput

func JSONInput(req *http.Request) interface{}

JSONInput extracts the de-serialized input from the context of the request.

func PanicHandler

func PanicHandler(next http.Handler) http.Handler

PanicHandler middleware recovers from panic in underlying handlers and sends HTTP 500 to the client when panic happens.

func PermissionHandler

func PermissionHandler(next http.Handler) http.Handler

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

func RoleHandler(next http.Handler) http.Handler

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.

func StrokeHandler

func StrokeHandler(next http.Handler) http.Handler

StrokeHandler defines a middleware that checks if the requested data is in the allowed area for the user and if the time is in the allowed range.


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.

func (JSONError) Error

func (je JSONError) Error() string

Error implements the error interface.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL