Documentation
¶
Index ¶
- Variables
- func Exec(req *http.Request, value interface{}) error
- func Register(contentType string, fn Binder)
- func RegisterCustomDecoder(fn CustomTypeDecoder, types []interface{}, fields []interface{})
- func RegisterTimeFormats(layouts ...string)
- type Bindable
- type Binder
- type ContenTypeBinder
- type CustomTypeDecoder
- type File
- type FileRequestTypeBinder
- type HTMLContentTypeBinder
- type JSONContentTypeBinder
- type RequestBinder
- type XMLRequestTypeBinder
Constants ¶
This section is empty.
Variables ¶
var ( // MaxFileMemory can be used to set the maximum size, in bytes, for files to be // stored in memory during uploaded for multipart requests. // See https://golang.org/pkg/net/http/#Request.ParseMultipartForm for more // information on how this impacts file uploads. MaxFileMemory int64 = 5 * 1024 * 1024 // BaseRequestBinder is an instance of the requestBinder, it comes with preconfigured // content type binders for HTML, JSON, XML and Files, as well as custom types decoders // for time.Time and nulls.Time BaseRequestBinder = NewRequestBinder( HTMLContentTypeBinder{ decoder: formDecoder, }, JSONContentTypeBinder{}, XMLRequestTypeBinder{}, FileRequestTypeBinder{ decoder: formDecoder, }, ) )
Functions ¶
func Exec ¶
Exec will bind the interface to the request.Body. The type of binding is dependent on the "Content-Type" for the request. If the type is "application/json" it will use "json.NewDecoder". If the type is "application/xml" it will use "xml.NewDecoder". The default binder is "https://github.com/monoculum/formam".
func RegisterCustomDecoder ¶ added in v0.13.0
func RegisterCustomDecoder(fn CustomTypeDecoder, types []interface{}, fields []interface{})
RegisterCustomDecoder allows to define custom decoders for certain types In the request.
func RegisterTimeFormats ¶
func RegisterTimeFormats(layouts ...string)
RegisterTimeFormats allows to add custom time layouts that the binder will be able to use for decoding.
Types ¶
type Bindable ¶ added in v0.14.1
Bindable when implemented, on a type will override any Binders that have been configured when using buffalo#Context.Bind
type Binder ¶
Binder takes a request and binds it to an interface. If there is a problem it should return an error.
type ContenTypeBinder ¶ added in v0.16.9
ContenTypeBinder are those capable of handling a request type like JSON or XML
type CustomTypeDecoder ¶
CustomTypeDecoder converts a custom type from the request into its exact type.
type File ¶ added in v0.10.3
type File struct { multipart.File *multipart.FileHeader }
File holds information regarding an uploaded file
type FileRequestTypeBinder ¶ added in v0.16.9
type FileRequestTypeBinder struct {
// contains filtered or unexported fields
}
FileRequestTypeBinder is in charge of binding File request types.
func (FileRequestTypeBinder) BinderFunc ¶ added in v0.16.9
func (ht FileRequestTypeBinder) BinderFunc() Binder
BinderFunc that will take care of the HTML File binding
func (FileRequestTypeBinder) ContentTypes ¶ added in v0.16.9
func (ht FileRequestTypeBinder) ContentTypes() []string
ContentTypes returns the list of content types for FileRequestTypeBinder
type HTMLContentTypeBinder ¶ added in v0.16.9
type HTMLContentTypeBinder struct {
// contains filtered or unexported fields
}
HTMLContentTypeBinder is in charge of binding HTML request types.
func (HTMLContentTypeBinder) BinderFunc ¶ added in v0.16.9
func (ht HTMLContentTypeBinder) BinderFunc() Binder
BinderFunc that will take care of the HTML binding
func (HTMLContentTypeBinder) ContentTypes ¶ added in v0.16.9
func (ht HTMLContentTypeBinder) ContentTypes() []string
ContentTypes that will be used to identify HTML requests
type JSONContentTypeBinder ¶ added in v0.16.9
type JSONContentTypeBinder struct{}
JSONContentTypeBinder is in charge of binding JSON request types.
func (JSONContentTypeBinder) BinderFunc ¶ added in v0.16.9
func (js JSONContentTypeBinder) BinderFunc() Binder
BinderFunc returns the Binder for this JSONRequestTypeBinder
func (JSONContentTypeBinder) ContentTypes ¶ added in v0.16.9
func (js JSONContentTypeBinder) ContentTypes() []string
ContentTypes that will be wired to this the JSON Binder
type RequestBinder ¶ added in v0.16.9
type RequestBinder struct {
// contains filtered or unexported fields
}
RequestBinder is in charge of binding multiple requests types to struct.
func NewRequestBinder ¶ added in v0.16.9
func NewRequestBinder(requestBinders ...ContenTypeBinder) *RequestBinder
NewRequestBinder creates our request binder with support for XML, JSON, HTTP and File request types.
func (*RequestBinder) Exec ¶ added in v0.16.9
func (rb *RequestBinder) Exec(req *http.Request, value interface{}) error
Exec binds a request with a passed value, depending on the content type It will look for the correct RequestTypeBinder and use it.
func (*RequestBinder) Register ¶ added in v0.16.9
func (rb *RequestBinder) Register(contentType string, fn Binder)
Register maps a request Content-Type (application/json) to a Binder.
type XMLRequestTypeBinder ¶ added in v0.16.9
type XMLRequestTypeBinder struct{}
XMLRequestTypeBinder is in charge of binding XML request types.
func (XMLRequestTypeBinder) BinderFunc ¶ added in v0.16.9
func (xm XMLRequestTypeBinder) BinderFunc() Binder
BinderFunc returns the Binder for this RequestTypeBinder
func (XMLRequestTypeBinder) ContentTypes ¶ added in v0.16.9
func (xm XMLRequestTypeBinder) ContentTypes() []string
ContentTypes that will be wired to this the XML Binder