Documentation ¶
Overview ¶
Package rv fills and validates values into structs from HTTP requests via reflection.
Index ¶
- func ParseJSONBody(body io.Reader) (map[string]interface{}, error)
- type BasicRequest
- type DefaultHandler
- type Field
- type FieldHandler
- func NewDefaultHandler(args []string) (FieldHandler, error)
- func NewOptionsHandler(args []string) (FieldHandler, error)
- func NewRangeHandler(args []string) (FieldHandler, error)
- func NewRequiredHandler(args []string) (FieldHandler, error)
- func NewSourceFieldHandler(args []string) (FieldHandler, error)
- func NewTypeHandler(args []string) (FieldHandler, error)
- type FieldHandlerCreator
- type FieldHandlers
- type ListHandler
- type OptionsHandler
- type PrecidenceFieldHandler
- type RangeHandler
- type Request
- type RequestHandler
- type RequiredHandler
- type Source
- type SourceFieldHandler
- type TypeHandler
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type BasicRequest ¶
BasicRequest implements the Request interface and can be used for testing or parsing requests from unsupported request types.
func (*BasicRequest) BodyForm ¶
func (r *BasicRequest) BodyForm() (url.Values, error)
BodyForm parses the Body string as a form
func (*BasicRequest) BodyJSON ¶
func (r *BasicRequest) BodyJSON() (map[string]interface{}, error)
BodyJSON parses the Body string as JSON
type DefaultHandler ¶
type DefaultHandler struct {
Default interface{}
}
func (DefaultHandler) Precidence ¶
func (h DefaultHandler) Precidence() int
goes before TypeHandler so the default string will be transformed into the right type
func (DefaultHandler) Run ¶
func (h DefaultHandler) Run(req Request, field *Field)
type FieldHandler ¶
func NewDefaultHandler ¶
func NewDefaultHandler(args []string) (FieldHandler, error)
func NewOptionsHandler ¶
func NewOptionsHandler(args []string) (FieldHandler, error)
func NewRangeHandler ¶
func NewRangeHandler(args []string) (FieldHandler, error)
func NewRequiredHandler ¶
func NewRequiredHandler(args []string) (FieldHandler, error)
func NewSourceFieldHandler ¶
func NewSourceFieldHandler(args []string) (FieldHandler, error)
func NewTypeHandler ¶
func NewTypeHandler(args []string) (FieldHandler, error)
type FieldHandlerCreator ¶
type FieldHandlerCreator func(args []string) (FieldHandler, error)
type FieldHandlers ¶
type FieldHandlers []FieldHandler
FieldHandlers is a sortable list of FieldHandlers
func (FieldHandlers) Less ¶
func (f FieldHandlers) Less(i, j int) bool
func (FieldHandlers) Swap ¶
func (f FieldHandlers) Swap(i, j int)
type ListHandler ¶
type ListHandler struct {
SubHandlers FieldHandlers
}
func (ListHandler) Run ¶
func (h ListHandler) Run(req Request, field *Field)
type OptionsHandler ¶
type OptionsHandler struct {
Options map[string]struct{}
}
func (OptionsHandler) Run ¶
func (h OptionsHandler) Run(req Request, field *Field)
type PrecidenceFieldHandler ¶
type PrecidenceFieldHandler interface { FieldHandler Precidence() int }
type RangeHandler ¶
func (RangeHandler) Run ¶
func (h RangeHandler) Run(req Request, field *Field)
type Request ¶
type Request interface { // QueryArgs returns the query parameters from the request URL QueryArgs() (url.Values, error) // PathArgs returns any parameters from the URL path, if supported by the request PathArgs() (map[string]string, error) // BodyJSON reads the request body and parses it as JSON BodyJSON() (map[string]interface{}, error) // BodyForm reads the request body and parses it as a form encoding BodyForm() (url.Values, error) }
Request is the interface to implement to allow rv to read values from a HTTP request.
type RequestHandler ¶
type RequestHandler struct { Fields map[string]FieldHandlers // contains filtered or unexported fields }
RequestHandler extracts and validates values from a request based on "rv" tags on the struct fields.
func NewRequestHandler ¶
func NewRequestHandler(requestStruct interface{}) (*RequestHandler, error)
NewRequestHandler builds a RequestHandler which will extract and validate values from a request based on the "rv" tags on the struct fields.
func (*RequestHandler) Bind ¶
func (h *RequestHandler) Bind(req Request, container interface{}) (argErr error, fieldErrors map[string]Field)
Bind searches the container for a field matching the RequestHandler's field type, then fills it by calling RequestHandler.Run with the specified Request and the matching field.
type RequiredHandler ¶
type RequiredHandler struct {
Required bool
}
func (RequiredHandler) Precidence ¶
func (h RequiredHandler) Precidence() int
func (RequiredHandler) Run ¶
func (h RequiredHandler) Run(req Request, field *Field)
type SourceFieldHandler ¶
SourceFieldHandler takes source and field names from the first argument in the rv struct tag, pulls the value from the request and puts it into the field.
func (SourceFieldHandler) Precidence ¶
func (h SourceFieldHandler) Precidence() int
func (SourceFieldHandler) Run ¶
func (h SourceFieldHandler) Run(r Request, f *Field)
type TypeHandler ¶
type TypeHandler struct {
Type string
}
func (TypeHandler) Precidence ¶
func (h TypeHandler) Precidence() int
func (TypeHandler) Run ¶
func (h TypeHandler) Run(r Request, f *Field)