validation

package
v0.0.0-...-2950954 Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2023 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Field

type Field vLib.FieldLevel

Field describes a field in a struct. It is used to get info about it for validation.

type Validator

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

func NewValidator

func NewValidator() *Validator

Our validator is setup only for 'en' locale. If we need to support other locales, we can add them here. But do not forget to add locales to the RegisterValidation too then.

func (*Validator) RegisterValidation

func (v *Validator) RegisterValidation(tag string, check func(Field) bool, errMsg string) error

RegisterValidation registers a new validation function with the validator. This function will be called when the validator encounters the tag.

func (*Validator) UnpackErrors

func (v *Validator) UnpackErrors(e error) []string

UnpackErrors unpacks the error returned by ValidateStruct into a slice of strings.

func (*Validator) ValidateStruct

func (v *Validator) ValidateStruct(value any) error

ValidateStruct validates the given struct. It validates it according to the tags on the struct. You can lookup available tags here. Or create custom tags by using RegisterValidation.

Jump to

Keyboard shortcuts

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