binding

package
v0.13.2 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2025 License: MIT, Apache-2.0, BSD-3-Clause Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MIMEPOSTForm          = "application/x-www-form-urlencoded"
	MIMEMultipartPOSTForm = "multipart/form-data"
)

Variables

View Source
var (
	Query         = queryBinding{}
	FormPost      = formPostBinding{}
	FormMultipart = formMultipartBinding{}
	Uri           = uriBinding{}
	Header        = headerBinding{}
	CustomBody    = &bodyBinding{name: "json", unmarshaller: json.Unmarshal}
)

These implement the Binding interface and can be used to bind the data present in the request to struct instances.

Functions

func Bind

func Bind(c *gin.Context, obj interface{}) error

func BindBody added in v0.1.9

func BindBody(c *gin.Context, obj interface{}) error

func BindQuery

func BindQuery(c *gin.Context, obj interface{}) error

BindQuery is a shortcut for c.MustBindWith(obj, binding.Query).

func BindUri added in v0.12.0

func BindUri(r *gin.Context, obj interface{}) error

ShouldBindUri binds the passed struct pointer using the specified binding engine.

func BindWith added in v0.12.0

func BindWith(c *gin.Context, obj interface{}, b Binding) error

MustBindWith binds the passed struct pointer using the specified binding engine. It will abort the request with HTTP 400 if any error occurs. See the binding package.

func NewReq

func NewReq[REQ any](c *gin.Context) (*REQ, error)

func SetTag

func SetTag(tag string)

func Validate

func Validate(obj interface{}) error

Types

type Binding

type Binding interface {
	Name() string
	Bind(*gin.Context, interface{}) 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.

Jump to

Keyboard shortcuts

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