validation

package
v1.10.0 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2021 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ContainerID defines the id to be used as the container registration id
	// of a validator instance, and as a base id of all other validation
	// package instances registered in the application container.
	ContainerID = rest.ContainerID + ".validation"

	// ContainerUniversalTranslatorID defines the id to be used
	// as the container registration id of an error message universal
	// translator.
	ContainerUniversalTranslatorID = ContainerID + ".universal-translator"

	// ContainerTranslatorID defines the id to be used
	// as the container registration id of an  error message translator.
	ContainerTranslatorID = ContainerID + ".translator"

	// ContainerParserID defines the id to be used
	// as the container registration id of an error parser instance.
	ContainerParserID = ContainerID + ".parser"
)
View Source
const (
	// Env defines the gapp-rest/validation package environment entry id
	// base string.
	Env = rest.Env + "_VALIDATION"

	// EnvLocale defines the name of the environment variable
	// to be checked for an overriding value for the validation error
	// parser translation local.
	EnvLocale = Env + "_LOCALE"
)

Variables

View Source
var (
	// Locale defines the default locale string to be used when
	// instantiating the error parser translator.
	Locale = "en"
)

Functions

func ErrNotFound added in v1.5.0

func ErrNotFound(locale string) error

ErrNotFound generates a translator not found error.

func NewProvider

func NewProvider() gapp.Provider

NewProvider will create a new validation provider instance

Types

type Parser

type Parser interface {
	Parse(ctx *gin.Context, val interface{}, errs validator.ValidationErrors) (*envelope.Envelope, error)
}

Parser defines the interface to a error parsing class used to convert a validation error into a envelope error

func NewParser

func NewParser(strategy ParserStrategy) (Parser, error)

NewParser instantiate a new validation parser instance

type ParserStrategy

type ParserStrategy func(ctx *gin.Context, val interface{}, err validator.FieldError) (*envelope.Error, error)

ParserStrategy is a function type used to define a calling interface of a function responsible to parse a validation error into an envelope error information

func NewParserStrategy

func NewParserStrategy(translator ut.Translator) (ParserStrategy, error)

NewParserStrategy instantiate a new default error parser strategy used by the parser to convert a validation error into an envelope error

type Validator

type Validator func(ctx *gin.Context, val interface{}) (*envelope.Envelope, error)

Validator is a function type used to define a calling interface of function responsible to validate an instance of a structure and return a initialized response envelope with the founded errors

func NewValidator

func NewValidator(validate *validator.Validate, parser Parser) (Validator, error)

NewValidator instantiates a new validation function

Jump to

Keyboard shortcuts

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