validation

package
v0.0.0-...-a8b8e24 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2024 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var EmptyOrWhitespaceOnlyRE = regexp.MustCompile(`^\s*$`)

EmptyOrWhitespaceOnlyRE is a regex that checks for blank or whitespace only strings

Functions

func NewError

func NewError(violations []*FieldViolation) error

NewError creates new validation error for field violoations.

func NewPlainError

func NewPlainError(fv *FieldViolation) error

NewPlainError creates new validation error.

Types

type FieldViolation

type FieldViolation struct {
	Field       string
	Description string
}

FieldViolation represents custom bad request error field violation error option.

func RequiredField

func RequiredField(field, fieldName, resourceName string) *FieldViolation

RequiredField verifies that the given field is not empty

type Options

type Options struct {
	Target          string
	Request         interface{}
	RequiredDefault bool
	Rules           Rules
}

Options represent configuration option for validator

type Rules

type Rules map[string][]string

Rules represents rules for fields with name and rules

type Validator

type Validator struct {
	Opts Options // Opts contains all the options for validator
}

Validator is a validator with options

func New

func New(opts Options) *Validator

New returns a new validator object with provided options

func (*Validator) Validate

func (v *Validator) Validate() error

Validate validates the validation object raise the error if any

Jump to

Keyboard shortcuts

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