validator

package
v0.0.0-...-7b1540a Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2020 License: BSD-2-Clause Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	IntRegxString         = "^\\d+$"
	EmailRegexString      = "" /* 1277-byte string literal not displayed */
	UUIDRegexStringString = "^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$"
)

Variables

Functions

func EmailRequired

func EmailRequired(value string) bool

func InterRequired

func InterRequired(value string) bool

func NewValidator

func NewValidator() *validator

Constructor for validator

func NewValidatorNote

func NewValidatorNote(fieldName string, rules validatorRules) *validatorNode

Constructor for validatorNode

func NewValidatorRule

func NewValidatorRule(name string, expect string, errorMessage string) *validatorRule

Constructor for validatorRule

func RegisterLibrary

func RegisterLibrary(key string, validateFunc ValidateFunc)

Register your own idea by this method It is not goroutine safe

func RemoveNodeByName

func RemoveNodeByName(nodes validatorNodes, name string) validatorNodes

Remove Node By Name

func UuidRequired

func UuidRequired(value string) bool

func Validate

func Validate(value string, validFunc ValidFunc) bool

Types

type SimpleValidateLibrary

type SimpleValidateLibrary map[string]ValidateFunc

Implement ValidateLibrary

func (SimpleValidateLibrary) LookForValidateFunc

func (s SimpleValidateLibrary) LookForValidateFunc(key string) ValidateFunc

Get ValidateFunc by key It would course panic if key does not exist

func (SimpleValidateLibrary) Register

func (s SimpleValidateLibrary) Register(key string, validateFunc ValidateFunc)

Register your ValidateFunc to Library It would course panic if key has already exist

func (SimpleValidateLibrary) Validate

func (s SimpleValidateLibrary) Validate(field reflect.Value, node *validatorNode) ValidateErrorNodes

Validate field if is legal

type ValidFunc

type ValidFunc func(value interface{}) bool

type ValidateError

type ValidateError struct {
	FieldName          string              `json:"field_name"`
	ValidateErrorNodes *ValidateErrorNodes `json:"validate_error_nodes"`
}

func NewValidateError

func NewValidateError(fieldName string, validateErrorNodes *ValidateErrorNodes) *ValidateError

Constructor for ValidateError

type ValidateErrorNode

type ValidateErrorNode struct {
	Code         string `json:"code"`
	ErrorMessage string `json:"error_message"`
}

func NewValidateErrorNode

func NewValidateErrorNode(code string, errorMessage string) *ValidateErrorNode

Constructor for ValidateErrorNode

type ValidateErrorNodes

type ValidateErrorNodes []*ValidateErrorNode

func NewValidateErrorNodes

func NewValidateErrorNodes(validateErrorNode ...*ValidateErrorNode) *ValidateErrorNodes

Constructor for ValidateErrorNodes

type ValidateErrors

type ValidateErrors []*ValidateError

func (ValidateErrors) Error

func (v ValidateErrors) Error() string

Implement error

type ValidateFunc

type ValidateFunc func(reflect.Value, *validatorRule) error

Validate data if it is valid ValidateFunc must register to ValidateLibrary or it won't be worked

type ValidateLibrary

type ValidateLibrary interface {
	Register(key string, validateFunc ValidateFunc)
	Validate(field reflect.Value, node *validatorNode) ValidateErrorNodes
	LookForValidateFunc(key string) ValidateFunc
}

ValidateLibrary interface

type Validator

type Validator interface {
	RunValidators(interface{}) ValidateError
}

Validator interface

Jump to

Keyboard shortcuts

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