playground

package
v0.9.4 Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2022 License: MIT Imports: 6 Imported by: 1

Documentation

Overview

Package playground is a wrapper of the original "github.com/go-playground/validator" and "github.com/go-playground/mold" library.

All of the validation and modifier tags from both libraries can still be used here.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrRequiredName = errors.New("required name")
	ErrRequiredFn   = errors.New("required function")
	ErrUnknownType  = errors.New("unknown type")
)

List of errors.

Functions

This section is empty.

Types

type Validator

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

Validator is validator and modifier client.

func New

func New(autoMod bool) *Validator

New to create new validator and modifier. Pass true if you want to modify the data automatically before validate.

func (*Validator) Modify

func (v *Validator) Modify(data interface{}) error

Modify to modify/set struct field value according to modifier tag. Param `data` should be a pointer.

func (*Validator) RegisterModifier

func (v *Validator) RegisterModifier(name string, fn func(string) string) error

RegisterModifier to register custom modifier.

func (*Validator) RegisterValidator

func (v *Validator) RegisterValidator(name string, fn func(interface{}, ...string) bool) error

RegisterValidator to register custom validator.

func (*Validator) RegisterValidatorError

func (v *Validator) RegisterValidatorError(name string, fn func(string, ...string) error) error

RegisterValidatorError to register custom error message handling.

func (*Validator) Validate

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

Validate to validate struct field value according to validator tag. Will modify/set the data if you turn on the autoMod. Param `data` should be a pointer.

Jump to

Keyboard shortcuts

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