validators

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2025 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package validators contains the validation functions for the application. these specificially relate to the prompts/questions asked to the user and validating the user input.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NotZero

func NotZero[T Validatable](v T) error

NotZero validates that the value is not zero. It returns an error if the value is zero.

Types

type Validatable added in v0.3.0

type Validatable interface {
	string | []string
}

type Validate added in v0.3.0

type Validate struct {
	Required  bool          `yaml:"required"`
	MinLength int           `yaml:"min"`
	MaxLength int           `yaml:"max"`
	Match     ValidateMatch `yaml:"match"`
}

Validate is a struct the holds the configuration for a validator.

type ValidateMatch added in v0.3.0

type ValidateMatch struct {
	Regex   string `yaml:"regex"`
	Message string `yaml:"message"`
}

type Validator

type Validator[T any] func(v T) error

func Combine

func Combine[T any](validators ...Validator[T]) Validator[T]

func GetValidatorFuncs added in v0.3.0

func GetValidatorFuncs[T Validatable](v Validate) []Validator[T]

GetValidatorFuncs converts a Validate struct into a slice of validator functions.

func Match added in v0.3.0

func Match[T Validatable](re string, msg string) Validator[T]

func MaxLength

func MaxLength[T any](m int) Validator[T]

MaxLength validates that the value is at most m long.

func MinLength

func MinLength[T Validatable](m int) Validator[T]

MinLength validates that the value is at least m long.

Jump to

Keyboard shortcuts

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