validator

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2023 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Builder

type Builder struct {
	// contains filtered or unexported fields
}

Builder is type to build validator

func NewBuilder

func NewBuilder() *Builder

NewBuilder initializes builder

func (*Builder) Build

func (b *Builder) Build() (Validator, error)

Build builds the validator

func (*Builder) Validate

func (b *Builder) Validate(s interface{}) error

Validate validates the type for any violation

func (*Builder) WithFieldValidations

func (b *Builder) WithFieldValidations(fieldValidations []FieldValidation) *Builder

WithFieldValidations tells builder to include custom field validation

func (*Builder) WithStructValidations

func (b *Builder) WithStructValidations(structValidations []StructValidation) *Builder

WithStructValidations tells builder to include custom struct validation

func (*Builder) WithTranslations

func (b *Builder) WithTranslations(translations []Translation) *Builder

WithTranslations tells builder to include custom translation

type FieldError

type FieldError map[string]string

FieldError is error with key is field name and value is all errors for that field

func (FieldError) Error

func (d FieldError) Error() string

Error returns error that represent the field error

func (FieldError) JSON

func (d FieldError) JSON() []byte

JSON converts field error into its JSON representation

type FieldValidation

type FieldValidation struct {
	Tag  string
	Func validator.Func
}

FieldValidation is a type to describe how to validate a field

type StructValidation

type StructValidation struct {
	Type interface{}
	Func validator.StructLevelFunc
}

StructValidation is a type to describe how to validate a struct

type Translation

type Translation struct {
	Tag             string
	Message         string
	Override        bool
	TranslationFunc func(ut.Translator, validator.FieldError) string
}

Translation is a type to describe how to translate

type Validator

type Validator interface {
	Validate(interface{}) error
}

Validator is contract to do validation

Jump to

Keyboard shortcuts

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