form

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Jul 10, 2026 License: Apache-2.0 Imports: 8 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Json = xun.Json
)

Functions

This section is empty.

Types

type TEntity

type TEntity[T any] struct {
	Data   T                 `json:"data"`
	Errors map[string]string `json:"errors"`
}

TEntity is a struct that contains the data and errors.

It is used by the Bind functions to return the data and errors.

func BindForm

func BindForm[T any](req *http.Request) (*TEntity[T], error)

BindForm binds the request body to the given struct.

It supports application/x-www-form-urlencoded, multipart/form-data.

If the request body is empty or the decoding fails, it returns an error.

func BindJson

func BindJson[T any](req *http.Request) (*TEntity[T], error)

BindJson binds the JSON request body to the given struct.

It attempts to decode the JSON body into the specified type.

If the decoding fails, it returns an error.

func BindQuery

func BindQuery[T any](req *http.Request) (*TEntity[T], error)

BindQuery binds the query string to the given struct.

func (*TEntity[T]) Error added in v1.1.5

func (t *TEntity[T]) Error() string

func (*TEntity[T]) Validate

func (t *TEntity[T]) Validate(languages ...string) bool

Validate checks the data against the validation rules and populates errors if any.

It uses the specified languages to find an appropriate validator and translates the error messages. Returns true if validation passes, otherwise false.

type Validator

type Validator struct {
	*validator.Validate
	Translator ut.Translator
}

Validator validates struct and field values.

It uses the specified languages to find an appropriate validator and translates the error messages.

func AddValidator

func AddValidator(trans ut.Translator, register func(v *validator.Validate, trans ut.Translator) (err error)) *Validator

AddValidator adds a new validator and translator to the map.

It also registers the translations for the default locale.

Jump to

Keyboard shortcuts

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