validation

package
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2023 License: MIT Imports: 10 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Language added in v0.0.2

type Language string
const (
	English Language = "en"
	Spanish Language = "es"
)

type Tag added in v0.0.7

type Tag string
const (
	Struct Tag = "struct"
	Json   Tag = "json"
)

type ValidatorMessageTranslator added in v0.0.5

type ValidatorMessageTranslator struct {
	Bundle *i18n.Bundle
}

func NewValidatorMessageTranslator added in v0.0.5

func NewValidatorMessageTranslator(tagName Tag) *ValidatorMessageTranslator

NewValidatorMessageTranslator is a function that allows you to create a new instance of the ValidatorMessageTranslator struct. The tagName parameter is the tag name that will be used to validate the struct.

The tagName parameter can be:

  • Struct: to validate the struct using the tag name of the struct.
  • Json: to validate the struct using the tag name of the json.

func (*ValidatorMessageTranslator) AddCustomMustParseMessageFileBytes added in v0.0.6

func (t *ValidatorMessageTranslator) AddCustomMustParseMessageFileBytes(fileBytes []byte, filename string)

AddCustomMustParseMessageFileBytes is a function that allows you to add custom messages to the validator. The fileBytes parameter is the content of the file to be added. The filename parameter is the name of the file to be added. It must be in the format: active.{language}.toml (e.g. active.fr.toml)

The format of the file must be as follows: [is-hola] # tag one = "The field %s must be hola" # message other = "The field %s must be hola" # message

[is-required] one = "The field %s is required" other = "The field %s is required"

func (*ValidatorMessageTranslator) AddCustomMustParseMessageFileBytesFromURL added in v0.0.6

func (t *ValidatorMessageTranslator) AddCustomMustParseMessageFileBytesFromURL(url string, filename string)

AddCustomMustParseMessageFileBytesFromURL is a function that allows you to add custom messages to the validator. The url parameter is the url of the file to be added.

The format of the file must be as follows: [is-hola] # tag one = "The field %s must be hola" # message other = "The field %s must be hola" # message

[is-required] one = "The field %s is required" other = "The field %s is required"

func (*ValidatorMessageTranslator) ValidateSchema added in v0.0.5

func (t *ValidatorMessageTranslator) ValidateSchema(lang string, data interface{}) error

ValidateSchema is a function that allows you to validate the schema of a struct. The lang parameter is the language in which the error messages will be returned. The data parameter is the struct to be validated.

Jump to

Keyboard shortcuts

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