srvalidation

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2022 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ContainerID defines the id to be used
	// as the container registration id of a validation.
	ContainerID = slaterest.ContainerID + ".validation"

	// ContainerUniversalTranslatorID defines the id to be used
	// as the container registration id of a universal translator.
	ContainerUniversalTranslatorID = ContainerID + ".universal_translator"

	// ContainerTranslatorID defines the id to be used
	// as the container registration id of a 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 (
	// EnvID defines the slate.slaterest.validation package base environment variable name.
	EnvID = slaterest.EnvID + "_VALIDATION"
)

Variables

View Source
var (
	// Locale defines the default locale string to be used when
	// instantiating the translator.
	Locale = senv.String(EnvID+"_LOCALE", "en")
)

Functions

func GetTranslator

func GetTranslator(c slate.ServiceContainer) (ut.Translator, error)

GetTranslator will try to retrieve the registered translator instance from the application service container.

func GetUniversalTranslator

func GetUniversalTranslator(c slate.ServiceContainer) (*ut.UniversalTranslator, error)

GetUniversalTranslator will try to retrieve the registered universal translator instance from the application service container.

Types

type Parser

type Parser interface {
	Parse(val interface{}, errs validator.ValidationErrors) (*srenvelope.Envelope, error)
	AddError(err string, code int)
}

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

func GetParser

func GetParser(c slate.ServiceContainer) (Parser, error)

GetParser will try to retrieve the registered error perser instance from the application service container.

func NewParser

func NewParser(translator ut.Translator) (Parser, error)

NewParser instantiate a new validation parser instance

type Provider

type Provider struct{}

Provider @todo doc

func (Provider) Boot

Boot will start the validation package

func (Provider) Register

func (p Provider) Register(c slate.ServiceContainer) error

Register will register the validation package instances in the application container

type Validator

type Validator func(val interface{}) (*srenvelope.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 an initialized response envelope with the founded errors

func GetValidator

func GetValidator(c slate.ServiceContainer) (Validator, error)

GetValidator will try to retrieve the registered validator instance from the application service container.

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