validate

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2024 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package validate provides an easy way to validate the data contained in structs, typically being DTOs containing user input.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Check

func Check[T any](v *Validator, value T, validatorFunc ValidatorFunc[T], key string)

Check checks if value passes the validatorFunc. The provided key is used for creating the errors map of the Validator.

func IsNotEmpty

func IsNotEmpty(value string) (bool, string)

IsNotEmpty checks that the provided value is not empty.

func IsValidTimeZone

func IsValidTimeZone(value string) (bool, string)

IsValidTimeZone checks if the provided value is a valid IANA timezone.

Types

type ValidatedType added in v0.1.1

type ValidatedType interface {
	Validate() *Validator
}

ValidatedType is implemented by any struct with a Validate method.

type Validator

type Validator struct {
	Errors map[string]string
}

Validator is used to validate contents of structs using Check.

func New

func New() *Validator

New creates a new Validator.

func (*Validator) Valid

func (v *Validator) Valid() bool

Valid checks if a Validator has any errors.

type ValidatorFunc

type ValidatorFunc[T any] func(value T) (bool, string)

ValidatorFunc is the expected format used for validating data using Check.

func IsGreaterThanFunc

func IsGreaterThanFunc[T shared.IntType](value1 T) ValidatorFunc[T]

IsGreaterThanFunc checks if the provided value2 > value1.

func IsGreaterThanOrEqualFunc

func IsGreaterThanOrEqualFunc[T shared.IntType](value1 T) ValidatorFunc[T]

IsGreaterThanOrEqualFunc checks if the provided value2 >= value1.

func IsLesserThanFunc

func IsLesserThanFunc[T shared.IntType](value1 T) ValidatorFunc[T]

IsLesserThanFunc checks if the provided value2 < value1.

func IsLesserThanOrEqualFunc

func IsLesserThanOrEqualFunc[T shared.IntType](value1 T) ValidatorFunc[T]

IsLesserThanOrEqualFunc checks if the provided value2 <= value1.

Jump to

Keyboard shortcuts

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