Documentation ¶
Index ¶
- Constants
- func AdminAccess(req *Request) bool
- func Handler(e *Endpoint) http.Handler
- func LoggedUserAccess(req *Request) bool
- type Endpoint
- type Endpoints
- type ParamOptions
- type Request
- func (req *Request) ContentType() string
- func (req *Request) Created(obj interface{})
- func (req *Request) Endpoint() string
- func (req *Request) Error(e error)
- func (req *Request) JSONBody() (url.Values, error)
- func (req *Request) MuxVariables() url.Values
- func (req *Request) NoContent()
- func (req *Request) Ok(obj interface{})
- func (req *Request) ParamsBySource() (map[string]url.Values, error)
- func (r *Request) ParseParams() error
- func (req *Request) RenderJSON(code int, obj interface{})
- func (req *Request) String() string
- type RouteAuth
- type RouteHandler
Constants ¶
const ( // ContentTypeJSON represents the content type of a JSON request ContentTypeJSON = "application/json" // ContentTypeMultipartForm represents the content type of a multipart request ContentTypeMultipartForm = "multipart/form-data" )
Variables ¶
This section is empty.
Functions ¶
func AdminAccess ¶
AdminAccess is a auth middleware that filters out non admin users
func LoggedUserAccess ¶
LoggedUserAccess is a auth middleware that filters out anonymous users
Types ¶
type Endpoint ¶
type Endpoint struct { Verb string // Path is the path for the current component Path string // Auth is used to add a auth middleware Auth RouteAuth // Handler is the handler to call Handler RouteHandler // Params represents a list of params the endpoint needs Params interface{} }
Endpoint represents an HTTP endpoint
type ParamOptions ¶
type ParamOptions struct { // Ignore means the field should not been parsed // json:"-" Ignore bool // Name contains the name of the field in the payload // json:"my_field" Name string // Required means the request should fail with a Bad Request if the field is missing. // params:"required" Required bool // Trim means the field needs to be trimmed before being retrieved and checked // params:"trim" Trim bool // ValidateUUID means the field should contain a valid UUIDv4 // params:"uuid" ValidateUUID bool // ValidateOptionalBool means the field should either be empty or contain a bool // params:"bool" ValidateOptionalBool bool }
ParamOptions represent all the options for a field
func NewParamOptions ¶
func NewParamOptions(tags *reflect.StructTag) *ParamOptions
NewParamOptions returns a ParamOptions from a StructTag
func (*ParamOptions) ApplyTransformations ¶
func (opts *ParamOptions) ApplyTransformations(value string) string
ApplyTransformations applies all the wanted transformations to the given value
func (*ParamOptions) Validate ¶
func (opts *ParamOptions) Validate(value string) error
Validate checks the given value passes the options set
type Request ¶
type Request struct { ID string Response http.ResponseWriter Request *http.Request Params interface{} User *auth.User // contains filtered or unexported fields }
Request represent a client request
func (*Request) ContentType ¶
ContentType returns the content type of the current request
func (*Request) Created ¶
func (req *Request) Created(obj interface{})
Created sends a http.StatusCreated response with a JSON object attached It should be used for successful POST requests
func (*Request) Error ¶
Error sends an error to the client If the error is an instance of HTTPError, the returned code will match HTTPError.Code(). It returns a 500 if no code has been set.
func (*Request) MuxVariables ¶
MuxVariables returns the URL variables associated to the request
func (*Request) NoContent ¶
func (req *Request) NoContent()
NoContent sends a http.StatusNoContent response It should be used for successful DELETE requests
func (*Request) Ok ¶
func (req *Request) Ok(obj interface{})
Ok sends a http.StatusOK response with a JSON object attached It should be used for successful GET, PATCH, and PUR requests
func (*Request) ParamsBySource ¶
ParamsBySource returns a map of params ordered by their source (url, query, form, ...)
func (*Request) ParseParams ¶
ParseParams will parse the params from the given request, and store them into the endpoint
func (*Request) RenderJSON ¶
RenderJSON attaches a json object to the response
type RouteHandler ¶
RouteHandler is the function signature we nee