validate

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2021 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Init

func Init() error

Init initializes validate

func Validate

func Validate(v interface{}) error

Validate validates data

Types

type Option

type Option struct {
	Min int64
	Max int64
}

Option is RegexValidateRule option

type RegexValidateRule

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

RegexValidateRule contains an validate tag's info

func NewRule

func NewRule(tag, regexStr string, opt *Option) *RegexValidateRule

NewRule news a rule

func (*RegexValidateRule) Explain

func (r *RegexValidateRule) Explain() string

Explain explains the rule

func (*RegexValidateRule) Tag

func (r *RegexValidateRule) Tag() string

Tag returns the validate rule's tag

func (*RegexValidateRule) Validate

func (r *RegexValidateRule) Validate(s string) bool

Validate validates string

type Validator

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

Validator validates data not safe, use it after initialized

func NewValidator

func NewValidator() *Validator

NewValidator news a validator

func (*Validator) AddErrorTranslation4Tag

func (v *Validator) AddErrorTranslation4Tag(tag string) error

AddErrorTranslation4Tag adds translation for the errors of some tag, to make the error easier to understand

func (*Validator) RegisterRule

func (v *Validator) RegisterRule(r *RegexValidateRule) error

RegisterRule registers a custom validate rule

func (*Validator) Validate

func (v *Validator) Validate(i interface{}) error

Validate validates the input data

Jump to

Keyboard shortcuts

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