binder

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2025 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MIMEApplicationXML  = "application/xml"
	MIMETextXML         = "text/xml"
	MIMEApplicationForm = "application/x-www-form-urlencoded"
	MIMEMultipartForm   = "multipart/form-data"
	MIMEApplicationJSON = "application/json"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type BindUnmarshaler

type BindUnmarshaler interface {
	// UnmarshalParam decodes and assigns a value from an form or query param.
	UnmarshalParam(param string) error
}

type RequestBinder

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

func NewRequestBinder

func NewRequestBinder(validator Validator) RequestBinder

func (RequestBinder) Bind

func (b RequestBinder) Bind(ctx context.Context,
	ctype string,
	r *http.Request,
	destType reflect.Type,
) (reflect.Value, error)

*

  • Bind takes the incoming HTTP request, extracts the necessary data based on the request method,
  • and binds it to the provided destination type. It handles query parameters, path parameters,
  • and request body binding. It also performs validation on the bound data using the validator. *
  • Parameters:
  • - ctx: the context of the request
  • - ctype: the content type of the request body
  • - r: the incoming HTTP request
  • - destType: the reflect.Type of the destination object *
  • Returns:
  • - reflect.Value: the reflect.Value of the bound data
  • - error: an error if any binding or validation fails

type Validator

type Validator interface {
	Validate(value any) (bool, map[string]string)
}

Jump to

Keyboard shortcuts

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