validator

package
v0.0.0-...-d386c04 Latest Latest
Warning

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

Go to latest
Published: Feb 4, 2024 License: BSD-3-Clause Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Alphanumeric string = "^[a-zA-Z0-9]+$"
)
View Source
var (
	DNSName string = `^([a-zA-Z0-9_]{1}[a-zA-Z0-9_-]{0,62}){1}(\.[a-zA-Z0-9_]{1}[a-zA-Z0-9_-]{0,62})*[\._]?$`
)
View Source
var DefaultConfig = &Config{
	StopAtFirstError: true,
}

Functions

func IsAlphanumeric

func IsAlphanumeric(str string) bool

IsAlphanumeric checks if the string contains only letters and numbers. Empty string is invalid.

func IsDNSName

func IsDNSName(str string) bool

IsDNSName will validate the given string as a DNS name

func IsHostPort

func IsHostPort(str string) bool

IsHostPort validates the given string for usage with the various Dial() functions

func IsIP

func IsIP(str string) bool

IsIP checks if a string is either IP version 4 or 6. Alias for `net.ParseIP`

func IsPort

func IsPort(str string) bool

IsPort checks if a string represents a valid port

func Validate

func Validate(conf *Config, fns ...Fn) (err error)

Types

type Config

type Config struct {
	StopAtFirstError bool
}

type Fn

type Fn func() error

func Map

func Map[T any](items map[string]T, fn func(refId string, item T) error) Fn

func MapNotNil

func MapNotNil[K comparable, V any](prop string, values map[K]V) Fn

func MapRequired

func MapRequired[K comparable, V any](prop string, values map[K]V) Fn

func NumberGreaterThan

func NumberGreaterThan[T int | int32 | int64 | uint | uint32 | uint64 | float32 | float64](prop string, value T, target T) Fn

func NumberGreaterThanOrEqual

func NumberGreaterThanOrEqual[T int | int32 | int64 | uint | uint32 | uint64 | float32 | float64](prop string, value T, target T) Fn

func NumberInRange

func NumberInRange[T int | int32 | int64 | uint | uint32 | uint64 | float32 | float64](prop string, value T, min, max T) Fn

func NumberLessThan

func NumberLessThan[T int | int32 | int64 | uint | uint32 | uint64 | float32 | float64](prop string, value T, target T) Fn

func NumberLessThanOrEqual

func NumberLessThanOrEqual[T int | int32 | int64 | uint | uint32 | uint64 | float32 | float64](prop string, value T, target T) Fn

func PointerNotNil

func PointerNotNil[T any](prop string, value *T) Fn

func Slice

func Slice[T any](items []T, fn func(i int, item *T) error) Fn

func SliceRequired

func SliceRequired[T any](prop string, values []T) Fn

func StringAlphanumeric

func StringAlphanumeric(prop, value string) Fn

func StringHostPort

func StringHostPort(prop, value string) Fn

func StringIn

func StringIn(prop string, values []string, in []string) Fn

func StringLen

func StringLen(prop, value string, min, max int) Fn

func StringLenIfNotEmpty

func StringLenIfNotEmpty(prop, value string, min, max int) Fn

func StringOneOf

func StringOneOf(prop, value string, oneOf []string) Fn

func StringRequired

func StringRequired(prop, value string) Fn

func StringStartsWith

func StringStartsWith(prop, value, prefix string) Fn

func StringStartsWithIfNotEmpty

func StringStartsWithIfNotEmpty(prop, value, prefix string) Fn

func StringStartsWithOneOf

func StringStartsWithOneOf(prop, value string, prefixes []string) Fn

func StringUri

func StringUri(prop, value string) Fn

type Validator

type Validator interface {
	Validate() error
}

Jump to

Keyboard shortcuts

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