buffalo: github.com/gobuffalo/buffalo/binding Index | Files | Directories

package binding

import "github.com/gobuffalo/buffalo/binding"

Index

Package Files

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

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,
        },
    )
)

func Exec Uses

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 Uses

func Register(contentType string, fn Binder)

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

func RegisterCustomDecoder Uses

func RegisterCustomDecoder(fn CustomTypeDecoder, types []interface{}, fields []interface{})

RegisterCustomDecoder allows to define custom decoders for certain types In the request.

func RegisterTimeFormats Uses

func RegisterTimeFormats(layouts ...string)

RegisterTimeFormats allows to add custom time layouts that the binder will be able to use for decoding.

type Bindable Uses

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 Uses

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 Uses

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

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

type CustomTypeDecoder Uses

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

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

type File Uses

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

File holds information regarding an uploaded file

func (File) String Uses

func (f File) String() string

func (File) Valid Uses

func (f File) Valid() bool

Valid if there is an actual uploaded file

type FileRequestTypeBinder Uses

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

FileRequestTypeBinder is in charge of binding File request types.

func (FileRequestTypeBinder) BinderFunc Uses

func (ht FileRequestTypeBinder) BinderFunc() Binder

BinderFunc that will take care of the HTML File binding

func (FileRequestTypeBinder) ContentTypes Uses

func (ht FileRequestTypeBinder) ContentTypes() []string

ContentTypes returns the list of content types for FileRequestTypeBinder

type HTMLContentTypeBinder Uses

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

HTMLContentTypeBinder is in charge of binding HTML request types.

func (HTMLContentTypeBinder) BinderFunc Uses

func (ht HTMLContentTypeBinder) BinderFunc() Binder

BinderFunc that will take care of the HTML binding

func (HTMLContentTypeBinder) ContentTypes Uses

func (ht HTMLContentTypeBinder) ContentTypes() []string

ContentTypes that will be used to identify HTML requests

type JSONContentTypeBinder Uses

type JSONContentTypeBinder struct{}

JSONContentTypeBinder is in charge of binding JSON request types.

func (JSONContentTypeBinder) BinderFunc Uses

func (js JSONContentTypeBinder) BinderFunc() Binder

BinderFunc returns the Binder for this JSONRequestTypeBinder

func (JSONContentTypeBinder) ContentTypes Uses

func (js JSONContentTypeBinder) ContentTypes() []string

ContentTypes that will be wired to this the JSON Binder

type RequestBinder Uses

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

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

func NewRequestBinder Uses

func NewRequestBinder(requestBinders ...ContenTypeBinder) *RequestBinder

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

func (*RequestBinder) Exec Uses

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 Uses

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

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

type XMLRequestTypeBinder Uses

type XMLRequestTypeBinder struct{}

XMLRequestTypeBinder is in charge of binding XML request types.

func (XMLRequestTypeBinder) BinderFunc Uses

func (xm XMLRequestTypeBinder) BinderFunc() Binder

BinderFunc returns the Binder for this RequestTypeBinder

func (XMLRequestTypeBinder) ContentTypes Uses

func (xm XMLRequestTypeBinder) ContentTypes() []string

ContentTypes that will be wired to this the XML Binder

Directories

PathSynopsis
decoders

Package binding imports 14 packages (graph) and is imported by 39 packages. Updated 2020-09-05. Refresh now. Tools for package owners.