Documentation
¶
Index ¶
- Variables
- func Bind(r *http.Request, obj interface{}) error
- func BindBody(r *http.Request, obj interface{}) error
- func BindHeader(r *http.Request, obj interface{}) error
- func BindQuery(r *http.Request, obj interface{}) error
- func BindUri(r *http.Request, obj interface{}) error
- func BindWith(r *http.Request, obj interface{}, b Binding) error
- func MapHeader(ptr interface{}, h map[string][]string) error
- func NewReq[REQ any](r *http.Request) (*REQ, error)
- func SetByMultipartFormFile(value reflect.Value, field *reflect.StructField, files []*multipart.FileHeader) (isSet bool, err error)
- func SetTag(tag string)
- func Validate(obj interface{}) error
- type Binding
- type HeaderSource
- type MultipartSource
- type UriSource
Constants ¶
This section is empty.
Variables ¶
var ( Uri = uriBinding{} Query = queryBinding{} Header = headerBinding{} CustomBody = &bodyBinding{name: "json", unmarshaller: json.Unmarshal} FormPost = formPostBinding{} FormMultipart = formMultipartBinding{} )
These implement the Binding interface and can be used to bind the data present in the request to struct instances.
var Tag = "json"
var Validator = validator.DefaultValidator
Validator is the default validator which implements the StructValidator interface. It uses https://github.com/go-playground/validator/tree/v8.18.2 under the hood.
Functions ¶
func BindHeader ¶ added in v0.12.0
func BindWith ¶ added in v0.12.0
BindWith 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 SetByMultipartFormFile ¶
func SetByMultipartFormFile(value reflect.Value, field *reflect.StructField, files []*multipart.FileHeader) (isSet bool, err error)
Types ¶
type Binding ¶
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.
type HeaderSource ¶
func (HeaderSource) HasValue ¶ added in v0.12.1
func (hs HeaderSource) HasValue(key string) bool
func (HeaderSource) TrySet ¶
func (hs HeaderSource) TrySet(value reflect.Value, field *reflect.StructField, key string, opt mtos.SetOptions) (isSet bool, err error)
type MultipartSource ¶
func (*MultipartSource) HasValue ¶ added in v0.12.1
func (ms *MultipartSource) HasValue(key string) bool
func (*MultipartSource) TrySet ¶
func (ms *MultipartSource) TrySet(value reflect.Value, field *reflect.StructField, key string, opt mtos.SetOptions) (isSet bool, err error)
TrySet tries to set a value by the multipart request with the binding a form file