validator

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: May 7, 2022 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetValidate

func GetValidate() *validator.Validate

func Init

func Init(opts *Options)

func RegisterValidation

func RegisterValidation(tag, errMsg string, vf Validation) error

RegisterValidation register custom validation func.

func Struct

func Struct(data interface{}) error

func StructCtx

func StructCtx(ctx context.Context, data interface{}) error

func Var

func Var(f interface{}, rule string) error

func VarCtx

func VarCtx(ctx context.Context, f interface{}, rule string) error

Types

type FieldError

type FieldError struct {
	Field   string
	Message string
}

func (*FieldError) Error

func (e *FieldError) Error() string

type Options

type Options struct {
	Language string `json:"language" mapstructure:"language"`
	// Struct field tag
	Tag string `json:"tag" mapstructure:"tag"`
}

func NewOptions

func NewOptions() *Options

func (*Options) AddFlags

func (o *Options) AddFlags(fs *pflag.FlagSet)

type Validation

type Validation func(fl validator.FieldLevel) bool

Validation custom validation func.

type ValidationErrors

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

func (*ValidationErrors) Error

func (e *ValidationErrors) Error() string

func (*ValidationErrors) GetValidatorValidationErrors

func (e *ValidationErrors) GetValidatorValidationErrors() validator.ValidationErrors

func (*ValidationErrors) TranslateErrs

func (e *ValidationErrors) TranslateErrs() (errs []error)

func (*ValidationErrors) TranslateErrsMap

func (e *ValidationErrors) TranslateErrsMap() map[string]string

type Validator

type Validator interface {
	Struct(data interface{}) error
	StructCtx(ctx context.Context, data interface{}) error
	Var(f interface{}, rule string) error
	VarCtx(ctx context.Context, f interface{}, rule string) error
	WithTranslator(language string) Validator
	GetValidate() *validator.Validate
	RegisterValidation(tag, errMSg string, vf Validation) error
}

func New

func New(language, tag string) Validator

func WithTranslator

func WithTranslator(language string) Validator

WithTranslator set default translation.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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