Documentation

Index

Constants

This section is empty.

Variables

View Source
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

func Exec(req *http.Request, value interface{}) error

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 Register

func Register(contentType string, fn Binder)

Register maps a request Content-Type (application/json) to a Binder.

func RegisterCustomDecoder

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

type Bindable interface {
	Bind(*http.Request) error
}

Bindable when implemented, on a type will override any Binders that have been configured when using buffalo#Context.Bind

type Binder

type Binder func(*http.Request, interface{}) error

Binder takes a request and binds it to an interface. If there is a problem it should return an error.

type ContenTypeBinder

type ContenTypeBinder interface {
	BinderFunc() Binder
	ContentTypes() []string
}

ContenTypeBinder are those capable of handling a request type like JSON or XML

type CustomTypeDecoder

type CustomTypeDecoder func([]string) (interface{}, error)

CustomTypeDecoder converts a custom type from the request into its exact type.

type File

type File struct {
	multipart.File
	*multipart.FileHeader
}

File holds information regarding an uploaded file

func (File) String

func (f File) String() string

func (File) Valid

func (f File) Valid() bool

Valid if there is an actual uploaded file

type FileRequestTypeBinder

type FileRequestTypeBinder struct {
	// contains filtered or unexported fields
}

FileRequestTypeBinder is in charge of binding File request types.

func (FileRequestTypeBinder) BinderFunc

func (ht FileRequestTypeBinder) BinderFunc() Binder

BinderFunc that will take care of the HTML File binding

func (FileRequestTypeBinder) ContentTypes

func (ht FileRequestTypeBinder) ContentTypes() []string

ContentTypes returns the list of content types for FileRequestTypeBinder

type HTMLContentTypeBinder

type HTMLContentTypeBinder struct {
	// contains filtered or unexported fields
}

HTMLContentTypeBinder is in charge of binding HTML request types.

func (HTMLContentTypeBinder) BinderFunc

func (ht HTMLContentTypeBinder) BinderFunc() Binder

BinderFunc that will take care of the HTML binding

func (HTMLContentTypeBinder) ContentTypes

func (ht HTMLContentTypeBinder) ContentTypes() []string

ContentTypes that will be used to identify HTML requests

type JSONContentTypeBinder

type JSONContentTypeBinder struct{}

JSONContentTypeBinder is in charge of binding JSON request types.

func (JSONContentTypeBinder) BinderFunc

func (js JSONContentTypeBinder) BinderFunc() Binder

BinderFunc returns the Binder for this JSONRequestTypeBinder

func (JSONContentTypeBinder) ContentTypes

func (js JSONContentTypeBinder) ContentTypes() []string

ContentTypes that will be wired to this the JSON Binder

type RequestBinder

type RequestBinder struct {
	// contains filtered or unexported fields
}

RequestBinder is in charge of binding multiple requests types to struct.

func NewRequestBinder

func NewRequestBinder(requestBinders ...ContenTypeBinder) *RequestBinder

NewRequestBinder creates our request binder with support for XML, JSON, HTTP and File request types.

func (*RequestBinder) Exec

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

func (rb *RequestBinder) Register(contentType string, fn Binder)

Register maps a request Content-Type (application/json) to a Binder.

type XMLRequestTypeBinder

type XMLRequestTypeBinder struct{}

XMLRequestTypeBinder is in charge of binding XML request types.

func (XMLRequestTypeBinder) BinderFunc

func (xm XMLRequestTypeBinder) BinderFunc() Binder

BinderFunc returns the Binder for this RequestTypeBinder

func (XMLRequestTypeBinder) ContentTypes

func (xm XMLRequestTypeBinder) ContentTypes() []string

ContentTypes that will be wired to this the XML Binder

Directories

Path Synopsis