import "github.com/gobuffalo/buffalo/binding"
bindable.go binding.go file.go file_request_type_binder.go html_content_type_binder.go json_content_type_binder.go request_binder.go types.go xml_request_type_binder.go
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, }, ) )
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".
Register maps a request Content-Type (application/json) to a Binder.
func RegisterCustomDecoder(fn CustomTypeDecoder, types []interface{}, fields []interface{})
RegisterCustomDecoder allows to define custom decoders for certain types In the request.
RegisterTimeFormats allows to add custom time layouts that the binder will be able to use for decoding.
Bindable when implemented, on a type will override any Binders that have been configured when using buffalo#Context.Bind
Binder takes a request and binds it to an interface. If there is a problem it should return an error.
ContenTypeBinder are those capable of handling a request type like JSON or XML
CustomTypeDecoder converts a custom type from the request into its exact type.
type File struct { multipart.File *multipart.FileHeader }
File holds information regarding an uploaded file
Valid if there is an actual uploaded file
type FileRequestTypeBinder struct {
// contains filtered or unexported fields
}
FileRequestTypeBinder is in charge of binding File request types.
func (ht FileRequestTypeBinder) BinderFunc() Binder
BinderFunc that will take care of the HTML File binding
func (ht FileRequestTypeBinder) ContentTypes() []string
ContentTypes returns the list of content types for FileRequestTypeBinder
type HTMLContentTypeBinder struct {
// contains filtered or unexported fields
}
HTMLContentTypeBinder is in charge of binding HTML request types.
func (ht HTMLContentTypeBinder) BinderFunc() Binder
BinderFunc that will take care of the HTML binding
func (ht HTMLContentTypeBinder) ContentTypes() []string
ContentTypes that will be used to identify HTML requests
type JSONContentTypeBinder struct{}
JSONContentTypeBinder is in charge of binding JSON request types.
func (js JSONContentTypeBinder) BinderFunc() Binder
BinderFunc returns the Binder for this JSONRequestTypeBinder
func (js JSONContentTypeBinder) ContentTypes() []string
ContentTypes that will be wired to this the JSON Binder
type RequestBinder struct {
// contains filtered or unexported fields
}
RequestBinder is in charge of binding multiple requests types to struct.
func NewRequestBinder(requestBinders ...ContenTypeBinder) *RequestBinder
NewRequestBinder creates our request binder with support for XML, JSON, HTTP and File request types.
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 (rb *RequestBinder) Register(contentType string, fn Binder)
Register maps a request Content-Type (application/json) to a Binder.
type XMLRequestTypeBinder struct{}
XMLRequestTypeBinder is in charge of binding XML request types.
func (xm XMLRequestTypeBinder) BinderFunc() Binder
BinderFunc returns the Binder for this RequestTypeBinder
func (xm XMLRequestTypeBinder) ContentTypes() []string
ContentTypes that will be wired to this the XML Binder
Path | Synopsis |
---|---|
decoders |
Package binding imports 14 packages (graph) and is imported by 39 packages. Updated 2020-09-05. Refresh now. Tools for package owners.