binding

package
v0.0.0-...-a84335b Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2024 License: AGPL-3.0 Imports: 9 Imported by: 0

Documentation

Overview

Package binding provides functions for binding input to internal parameter structures and verifying those bindings.

Index

Constants

View Source
const (
	// MIMEJSON is the mime type string for json
	MIMEJSON = "application/json"
	// MIMEPOSTForm is the mime type string for form bodies
	MIMEPOSTForm = "application/x-www-form-urlencoded"
	// MIMEMultipartPostForm is the mime type string for multipart bodies
	MIMEMultipartPostForm = "mulitpart/form-data"
)

Variables

View Source
var (
	// JSON binding
	JSON = jsonBinding{}
	// Form binding
	Form = formBinding{}
	// Query binding
	Query = queryBinding{}
	// FormPost binding
	FormPost = formPostBinding{}
	// FormMultipart binding
	FormMultipart = formMultipartBinding{}
	// Path binding binds the uri path
	Path = uriBinding{}
)

Functions

func Bind

func Bind(r *http.Request, dst any) error

Bind takes a request and applies the body to the destination based on the content-type.

func BindQuery

func BindQuery(r *http.Request, dst any) error

BindQuery takes the request query parameters and binds them to the destination struct

func BindVars

func BindVars(r *http.Request, dst any) error

BindVars takes the request path vars and binds them to the destination struct

Types

type Body

type Body interface {
	Request
	BindBody([]byte, any) error
}

Body interfaces are like Binding interfaces, but they can also accept the encoded data as a byte slice in addition to a io.Reader from a request.

type Request

type Request interface {
	Name() string
	Bind(*http.Request, any) error
}

Request interfaces represent a method for taking a request body, query parameters, or form body, and mapping it to a destination object.

type URI

type URI interface {
	Request
	BindURI(map[string]string, any) error
}

URI interfaces can bind the URI params from mux.Vars to a struct.

Jump to

Keyboard shortcuts

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