hail

package module
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Feb 4, 2024 License: MIT Imports: 6 Imported by: 0

README

Hail

Hail is a golang library for validating data during ingestion.

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Accepted

func Accepted() func(value string) error

The value under validation must be "yes" or "on". This is useful for validating checkbox/boolean html form fields such as "Terms of Service" acceptance.

func CountryCodeISO3166Alpha2

func CountryCodeISO3166Alpha2() func(value string) error

func CountryCodeISO3166Alpha3

func CountryCodeISO3166Alpha3() func(value string) error

func Max

func Max[T constraints.Ordered](max T) func(value T) error

The field under validation must be less than or equal to the maximum value.

func Min

func Min[T constraints.Ordered](min T) func(value T) error

The field under validation must be more than or equal to the minimum value.

func PrintableASCII added in v0.2.0

func PrintableASCII() func(value string) error

func PrintableUTF8 added in v0.4.0

func PrintableUTF8() func(value string) error

func Regex

func Regex(pattern string) func(value string) error

The field under validation must match the given regular expression.

func Size added in v0.3.0

func Size[T ~string | ~[]S, S any](min uint, max uint) func(value T) error

Types

type ErrASCII added in v0.2.0

type ErrASCII struct {
	// contains filtered or unexported fields
}

func NewErrASCII added in v0.5.0

func NewErrASCII(value string) ErrASCII

func (ErrASCII) Error added in v0.2.0

func (err ErrASCII) Error() string

type ErrAccepted

type ErrAccepted struct {
	// contains filtered or unexported fields
}

func NewErrAccepted added in v0.5.0

func NewErrAccepted(value string) ErrAccepted

func (ErrAccepted) Error

func (err ErrAccepted) Error() string

type ErrCountryCode

type ErrCountryCode struct {
	// contains filtered or unexported fields
}

func NewErrCountryCode added in v0.5.0

func NewErrCountryCode(value string, format string) ErrCountryCode

func (ErrCountryCode) Error

func (err ErrCountryCode) Error() string

type ErrMax

type ErrMax[T constraints.Ordered] struct {
	// contains filtered or unexported fields
}

func NewErrMax added in v0.5.0

func NewErrMax[T constraints.Ordered](value T, max T) ErrMax[T]

func (ErrMax[T]) Error

func (err ErrMax[T]) Error() string

type ErrMin

type ErrMin[T constraints.Ordered] struct {
	// contains filtered or unexported fields
}

func NewErrMin added in v0.5.0

func NewErrMin[T constraints.Ordered](value T, min T) ErrMin[T]

func (ErrMin[T]) Error

func (err ErrMin[T]) Error() string

type ErrRegex

type ErrRegex struct {
	// contains filtered or unexported fields
}

func NewErrRegex added in v0.5.0

func NewErrRegex(value string, pattern string) ErrRegex

func (ErrRegex) Error

func (err ErrRegex) Error() string

type ErrSize added in v0.3.0

type ErrSize[T ~string | ~[]S, S any] struct {
	// contains filtered or unexported fields
}

func NewErrSize added in v0.5.0

func NewErrSize[T ~string | ~[]S, S any](value T, min, max uint) ErrSize[T, S]

func (ErrSize[T, S]) Error added in v0.3.0

func (err ErrSize[T, S]) Error() string

type ErrUTF8 added in v0.4.0

type ErrUTF8 struct {
	// contains filtered or unexported fields
}

func NewErrUTF8 added in v0.5.0

func NewErrUTF8(value string) ErrUTF8

func (ErrUTF8) Error added in v0.4.0

func (err ErrUTF8) Error() string

type RuleSet

type RuleSet[T any] []func(value T) error

func Rule

func Rule[T any](rules ...func(value T) error) (RuleSet[T], error)
Example
package main

import (
	"fmt"

	"gitlab.com/JankTech/hail"
)

func main() {
	v := 123
	r, err := hail.Rule(hail.Min(130), hail.Max(110))
	if err != nil {
		panic(err)
	}

	ok, errs := r.Validate(v)
	if !ok {
		for _, err = range errs {
			fmt.Println(err.Error())
		}
	}

}
Output:

value 123 is less than min 130
value 123 is more than max 110

func (RuleSet[T]) Validate

func (rs RuleSet[T]) Validate(value T) (valid bool, validationErrors []error)

Jump to

Keyboard shortcuts

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