binding

package
v2.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 27, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ContentTypeBinary            = "application/octet-stream"
	ContentTypeForm              = "application/x-www-form-urlencoded"
	ContentTypeJSON              = "application/json"
	ContentTypeYaml              = "application/x-yaml"
	ContentTypeToml              = "application/toml"
	ContentTypeHTML              = "text/html"
	ContentTypeText              = "text/plain"
	ContentTypeXML               = "application/xml"
	ContentTypeXML2              = "text/xml"
	ContentTypeMultipartPostForm = "multipart/form-data"
	ContentTypeProtoBuf          = "application/x-protobuf"
	ContentTypeMsgPack           = "application/x-msgpack"
	ContentTypeMsgPack2          = "application/msgpack"
)

Variables

This section is empty.

Functions

func Registry

func Registry(b Binding) error

Types

type Binding

type Binding interface {
	ContentType() []string
	Bind(*http.Request, any) error
}

Binding describes the interface which needs to be implemented for binding the data present in the request such as JSON request body, query parameters or the form POST.

func Default

func Default(r *http.Request) Binding

func Get

func Get(contentType string) Binding

func NewJSONBinding

func NewJSONBinding(opts ...JSONBindingOption) Binding

type JSONBinding

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

func (*JSONBinding) Apply

func (binding *JSONBinding) Apply(opts ...JSONBindingOption)

func (*JSONBinding) Bind

func (binding *JSONBinding) Bind(r *http.Request, v any) error

func (*JSONBinding) ContentType

func (binding *JSONBinding) ContentType() []string

type JSONBindingOption

type JSONBindingOption func(*JSONBinding)

func WithDisallowUnknownFields

func WithDisallowUnknownFields(enable bool) JSONBindingOption

func WithUseNumber

func WithUseNumber(enable bool) JSONBindingOption

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL