validation

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2023 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package validation implements structure validation parsing functionalities so that a normalized envelope can be obtained while validation the structure content.

Index

Constants

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

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

	// TranslatorID defines the id to be used
	// as the container registration id of a translator.
	TranslatorID = ID + ".translator"

	// ParserID defines the id to be used
	// as the container registration id of an error parser instance.
	ParserID = ID + ".parser"
)
View Source
const (
	// EnvID defines the slate.api.validation package base environment variable name.
	EnvID = api.EnvID + "_VALIDATION"
)

Variables

View Source
var (
	// ErrTranslatorNotFound @todo doc
	ErrTranslatorNotFound = fmt.Errorf("translator not found")
)
View Source
var (
	// Locale defines the default locale string to be used when
	// instantiating the translator.
	Locale = env.String(EnvID+"_LOCALE", "en")
)

Functions

This section is empty.

Types

type IParser

type IParser interface {
	Parse(val interface{}, errs validator.ValidationErrors) (*envelope.Envelope, error)
	AddError(e string, code int)
}

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

func NewParser

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

NewParser instantiate a new validation parser instance

type Provider

type Provider struct{}

Provider @todo doc

func (Provider) Boot

func (p Provider) Boot(
	container ...slate.IContainer,
) error

Boot will start the validation package

func (Provider) Register

func (p Provider) Register(
	container ...slate.IContainer,
) error

Register will register the validation package instances in the application container

type Validator

type Validator func(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 an initialized response envelope with the founded error

func NewValidator

func NewValidator(
	validate *validator.Validate,
	parser IParser,
) (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