validator

package
v2.0.3 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2024 License: MIT Imports: 12 Imported by: 5

Documentation

Index

Constants

View Source
const (
	// Female gender female.
	Female = 0
	// Male gender male.
	Male = 1
)

Variables

View Source
var ErrUnexpected = errors.New("参数校验出错")

ErrUnexpected unexpected error.

Functions

func ParseErr

func ParseErr(err error) string

ParseErr parses the content of validation error.

func Verify

func Verify(obj interface{}) error

Verify checks the data validity of the exportable field of the structure according to the validate tag.

func VerifyVar

func VerifyVar(field interface{}, tag string) error

VerifyVar checks the data validity of the field according to the validate tag.

func VerifyVarWithValue

func VerifyVarWithValue(field, other interface{}, tag string) error

VerifyVarWithValue checks the data validity of the field against another field according to the validate tag.

Types

type BankCard

type BankCard string

BankCard bank card validator.

func NewBankCard

func NewBankCard(bankcard string) BankCard

NewBankCard new a bank card validator.

func (BankCard) IsValid

func (bc BankCard) IsValid() bool

IsValid checks the bank card is valid.

type CorpAccount

type CorpAccount string

CorpAccount corp account validator.

func NewCorpAccount

func NewCorpAccount(corpaccount string) CorpAccount

NewCorpAccount new a corp account validator.

func (CorpAccount) IsValid

func (ca CorpAccount) IsValid() bool

IsValid checks the corp account is valid.

type IdCard

type IdCard string

IdCard id card validator.

func NewIdCard

func NewIdCard(idcard string) IdCard

NewIdCard new an id card validator.

func (IdCard) GetBirthday

func (ic IdCard) GetBirthday() (time.Time, error)

GetBirthday gets the birthday recorded on id card.

func (IdCard) GetGender

func (ic IdCard) GetGender() (int, error)

GetGender gets the gender recorded on id card.

func (IdCard) IsFemale

func (ic IdCard) IsFemale() (bool, error)

IsFemale judges whether it is female.

func (IdCard) IsMale

func (ic IdCard) IsMale() (bool, error)

IsMale judges whether it is male.

func (IdCard) IsValid

func (ic IdCard) IsValid() bool

IsValid checks the id card is valid.

type USCC

type USCC string

USCC uscc validator.

func NewUSCC

func NewUSCC(uscc string) USCC

NewUSCC new an uscc validator.

func (USCC) IsValid

func (uscc USCC) IsValid() bool

IsValid checks the uscc is valid.

type Validator added in v2.0.3

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

Validator represents the validator structure.

func MustNewValidator added in v2.0.3

func MustNewValidator() *Validator

MustNewValidator must new a validator.

func NewValidator added in v2.0.3

func NewValidator() (*Validator, error)

NewValidator new a validator.

func (*Validator) Translate added in v2.0.3

func (v *Validator) Translate(err error) error

Translate translates the validation errors.

func (*Validator) TranslateAll added in v2.0.3

func (v *Validator) TranslateAll(err error) error

TranslateAll translates all validation errors.

func (*Validator) Validate added in v2.0.3

func (v *Validator) Validate(r *http.Request, data any) error

Validate validates the request and parsed data.

Jump to

Keyboard shortcuts

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