validator

package
v0.2.4 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2025 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ErrorSeparator = "; "
	FieldSeparator = " : "
)

Delimiters for text representation of errors.

Variables

View Source
var (
	// ErrNotFound is returned when data not found by identifier.
	ErrNotFound = errors.New("not found")

	// ErrDuplicateKey is returned when got duplicate key error from database.
	ErrDuplicateKey = errors.New("duplicate key")

	// ErrRequiredFieldMissed is returned when required param is empty in the request.
	ErrRequiredFieldMissed = errors.New("is required")
)

Functions

This section is empty.

Types

type ValidationError

type ValidationError struct {
	Name   string `json:"name"`
	Reason string `json:"reason"`
}

ValidationError contains field name and error message.

func NewValidationError

func NewValidationError(field, msg string) *ValidationError

NewValidationError creates and returns pointer to ValidationError.

func (*ValidationError) Error

func (ve *ValidationError) Error() string

Error represents an error condition, with the nil value representing no error.

type ValidationErrors

type ValidationErrors []ValidationError

ValidationErrors is an array of ValidationError's for use in custom error messages post validation.

func (ValidationErrors) Error

func (ves ValidationErrors) Error() string

Error represents an error condition, with the nil value representing no error.

type Validator

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

Validator is a wrapper for external validation package. Allows extending validation rules.

func New

func New() *Validator

New returns a new instance of Validator with sane defaults.

func (*Validator) Validate

func (v *Validator) Validate(i interface{}) error

Validate implement Validator interface.

Jump to

Keyboard shortcuts

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