validation

package
v0.4.19 Latest Latest
Warning

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

Go to latest
Published: May 10, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package validation provides the validation functions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterTranslation

func RegisterTranslation(tag, msg string) error

RegisterTranslation is shortcut of defaultValidator.RegisterTranslation that registers translations against the provided tag with given msg.

func RegisterValidation

func RegisterValidation(tag string, fn validator.Func) error

RegisterValidation is shortcut of defaultValidator.RegisterValidation that register custom validation with given tag, and it can be used in init.

func Validate

func Validate(v string, tagOrRules []interface{}) error

Validate validates the given string with tag.

func ValidateStruct

func ValidateStruct(s interface{}) error

ValidateStruct validates the struct

func ValidateValue

func ValidateValue(v interface{}, tag string) error

ValidateValue validates the value with the tag

Types

type CustomRule

type CustomRule struct {
	Tag  string
	Func CustomRuleFunc
	Err  error
}

CustomRule is the custom rule struct.

type CustomRuleFunc

type CustomRuleFunc = validator.Func

CustomRuleFunc custom rule check function.

type FieldLevel

type FieldLevel = validator.FieldLevel

FieldLevel is the field level interface.

type StructError

type StructError struct {
	Violations []Violation
}

StructError is the error returned by the validation of struct.

func (StructError) Error

func (s StructError) Error() string

Error returns the error message.

type Violation

type Violation struct {
	Tag         string
	Field       string
	Err         error
	Description string
}

Violation is the error returned by the validation.

func (Violation) Error

func (e Violation) Error() string

Error returns the error message.

Jump to

Keyboard shortcuts

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