binding

package
v0.0.0-...-fd52f74 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2022 License: BSD-3-Clause Imports: 10 Imported by: 0

Documentation

Overview

Package binding is used to bind request data into go objects.

Index

Constants

View Source
const (
	MIMEHTML              = "text/html"
	MIMEXML               = "application/xml"
	MIMEXML2              = "text/xml"
	MIMEPlain             = "text/plain"
	MIMEPOSTForm          = "application/x-www-form-urlencoded"
	MIMEMultipartPOSTForm = "multipart/form-data"
	MIMEPROTOBUF          = "application/x-protobuf"
	MIMEMSGPACK           = "application/x-msgpack"
	MIMEMSGPACK2          = "application/msgpack"
	MIMEYAML              = "application/x-yaml"
)

Content-Type MIME of the most common data formats.

Variables

View Source
var (
	JSON  = jsonBinding{}
	XML   = xmlBinding{}
	Form  = formBinding{}
	Query = queryBinding{}
	// FormPost      = formPostBinding{}
	// FormMultipart = formMultipartBinding{}
	ProtoBuf = protobufBinding{}
	MsgPack  = msgpackBinding{}
	YAML     = yamlBinding{}
	// URI           = uriBinding{}
	Header = headerBinding{}
)
View Source
var (
	JSONMimeApplication   = "application/json"
	JSONMimeText          = "text/json"
	JSONMimeJS            = "text/javascript"
	MsgPackMime           = "application/msgpack"
	MsgPackMimeX          = "application/x-msgpack"
	ProtoBufMime          = "application/x-protobuf"
	XMLMimeApplication    = "application/xml"
	XMLMimeText           = "text/xml"
	YAMLMime              = "application/x-yaml"
	MultipartPostFormMime = "multipart/form-data"
	PostFormMime          = "application/x-www-form-urlencoded"
)
View Source
var EnableDecoderDisallowUnknownFields = false

EnableDecoderDisallowUnknownFields is used to call the DisallowUnknownFields method on the JSON Decoder used to decode the reader into the interface. Enabling this makes it so the Decoder will return an error when the input contains keys which do not match exported fields in the destination.

View Source
var EnableDecoderUseNumber = false

EnableDecoderUseNumber is used to call the UseNumber method on the JSON Decoder used to decode the reader into the interface.

Functions

func Validate

func Validate(value interface{}, validators ...Validator) error

Types

type Binding

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

func Default

func Default(method string, contentType string) Binding

type Validator

type Validator interface {
	// ValidateStruct is the method that is called to validate a struct.
	ValidateStruct(interface{}) error

	// Validator is the method that is called to return the validator that is used to validate the struct.
	// For example the default validator will return an instance of github.com/go-playground/validator/v10's Validate struct.
	Validator() interface{}
}

Validator represents an interface that has to be implemented in order for it to be used as a validator.

Jump to

Keyboard shortcuts

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