Documentation ¶
Index ¶
- Constants
- Variables
- type Context
- type CreateContextFn
- type Error
- type Errors
- type Event
- type FieldError
- type HandlerFunc
- type Params
- type Router
- func (this *Router) Delete(path string, fns ...HandlerFunc)
- func (this *Router) Get(path string, fns ...HandlerFunc)
- func (this *Router) Post(path string, fns ...HandlerFunc)
- func (this *Router) Put(path string, fns ...HandlerFunc)
- func (this *Router) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (this *Router) SubRouter(path string) *Router
- func (this *Router) Use(middleware HandlerFunc)
- type ValidationError
- type Values
Constants ¶
const ( ErrCodeRequired = "required" // Value is required ErrCodeValueTooHigh = "value-too-high" // Numeric/date value is too high. Text field is too long. ErrCodeValueTooLow = "value-too-low" // Numeric/date value is too low. Text field is too short. ErrCodeDuplicate = "duplicate" // Duplicate. Eg username is taken or entity already exists ErrCodeSyntaxError = "syntax-error" // Invalid value. Unparseable/unreadable/not following conventions ErrCodeInvalidState = "invalid-state" // Value represents/would lead to an invalid state for the object ErrCodeNotFound = "not-found" // The resource pointed by the value was not found. Eg reference to non-existing entity )
const StatusValidationError = 422
Variables ¶
var ( ErrForbidden = NewError(http.StatusForbidden, "") ErrNotFound = NewError(http.StatusNotFound, "") ErrConflict = NewError(http.StatusConflict, "") ErrBadRequest = NewError(http.StatusBadRequest, "") )
var DateFormat = "2006-01-02"
DateFormat is the date format used when parsing a date in Params.GetDate()
Functions ¶
This section is empty.
Types ¶
type Context ¶
type Context struct { context.Context // R is the original http request object of the handler R *http.Request // W will write to the original response writer of the handler W http.ResponseWriter // Result holds the data to be returned to the client Result interface{} // Params holds the parameters of the url and querystring of the context's request. Params *Params // Values holds context specific values Values Values // contains filtered or unexported fields }
func (*Context) Err ¶
Err() returns any errors returned by the handlers If there are multiple errors, an error of type Errors is returned, allowing access to each individual error in the order that they were generated.
func (*Context) Next ¶
func (this *Context) Next()
Next() calls the next handler in the chain of handlers, if any. It can be used by middleware handlers to continue processing other handlers and delay execution of code until after these have finished.
func (*Context) ParseBody ¶
ParseBody parses the body of the request as a JSON string and unmarshals it into dst.
func (*Context) Stop ¶
func (this *Context) Stop()
Stop() stops the context from calling any remaining handlers that have not yet run. Note that handlers that have already run before the handler calling Stop() and that have called Next() on the context will still execute the code that comes after Next().
Example:
func Middleware(c Context) error { c.Next() // the next handler calls c.Stop() c.Debugf("Hello") // this will still get called return nil }
type Errors ¶
type Errors []error
Errors holds one or more errors returned by the handler functions executed on the context. The errors are arranged ordered by when they occured.
type FieldError ¶
type HandlerFunc ¶
type Params ¶
type Params struct {
// contains filtered or unexported fields
}
Params provides access to parameters in the URL and querystring of a request.
func (*Params) Get ¶
Get returns the given key's value from the request path parameters or querystring. The request path is searched first and overrides any querystring values with the same key.
func (*Params) GetDate ¶
GetDate returns the given key's value as a time.Time instance, parsed by the format set in the DateFormat variable. Returns the zero value for invalid or missing values. The request path is searched first and overrides any querystring values with the same key.
func (*Params) GetInt ¶
GetInt64 returns the given key's value as an int. Returns 0 for invalid or missing values. The request path is searched first and overrides any querystring values with the same key.
type Router ¶
type Router struct { CreateContext CreateContextFn // contains filtered or unexported fields }
func (*Router) Delete ¶
func (this *Router) Delete(path string, fns ...HandlerFunc)
func (*Router) Get ¶
func (this *Router) Get(path string, fns ...HandlerFunc)
func (*Router) Post ¶
func (this *Router) Post(path string, fns ...HandlerFunc)
func (*Router) Put ¶
func (this *Router) Put(path string, fns ...HandlerFunc)
func (*Router) Use ¶
func (this *Router) Use(middleware HandlerFunc)
type ValidationError ¶
type ValidationError struct {
Errors []*FieldError `json:"errors,omitempty"`
}
func NewValidationError ¶
func NewValidationError() *ValidationError
func (*ValidationError) AddError ¶
func (this *ValidationError) AddError(key string, errorCode string)
func (*ValidationError) AddErrorDetailed ¶
func (this *ValidationError) AddErrorDetailed(key string, errorCode string, data interface{}, hint string, hintArgs ...interface{})
func (*ValidationError) Error ¶
func (this *ValidationError) Error() string
func (*ValidationError) HasErrors ¶
func (this *ValidationError) HasErrors() bool
type Values ¶
type Values map[interface{}]interface{}
func (Values) Get ¶
func (this Values) Get(key interface{}) interface{}
Get returns the given key's value from the request path parameters or querystring. The request path is searched first, and overrides any querystring values with the same key.
func (Values) GetInt ¶
GetInt64 returns the given key's value as an int. Returns 0 for invalid or missing values.