validator

package
v1.2.0 Latest Latest
Warning

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

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

Documentation

Overview

Package validator provides functionality for validating and sanitizing data.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Blank

func Blank(value string) bool

Blank returns true if a value is an empty string.

func IsNumber

func IsNumber(value string) bool

IsNumber returns true if specified value is a number.

func MaxChars

func MaxChars(value string, n int) bool

MaxChars returns true if a value contains no more than n characters.

func MaxDuration

func MaxDuration(d, maxDuration time.Duration) bool

MaxDuration validates if a duration is within the maximum allowed duration.

func MinChars

func MinChars(value string, n int) bool

MinChars returns true if a value contains at least n characters.

func NotBlank

func NotBlank(value string) bool

NotBlank returns true if a value is not an empty string.

func PermittedValue

func PermittedValue[T comparable](value T, permittedValues ...T) bool

PermittedValue returns true if a value is in a list of permitted integers.

Types

type Validator

type Validator struct {
	FieldErrors    map[string]string
	NonFieldErrors []string
}

Validator is a struct that contains field errors and a non-field errors.

func (*Validator) AddFieldError

func (v *Validator) AddFieldError(key, message string)

AddFieldError adds an error message to the FieldErrors map.

func (*Validator) AddNonFieldError

func (v *Validator) AddNonFieldError(message string)

AddNonFieldError adds an error message to the NonFieldErrors slice.

func (*Validator) CheckField

func (v *Validator) CheckField(ok bool, key, message string)

CheckField adds an error message to the FieldErrors map only if a validation check is not passed.

func (*Validator) Valid

func (v *Validator) Valid() bool

Valid returns true if the FieldErrors map is empty, otherwise false.

Jump to

Keyboard shortcuts

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