constraints

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Empty validation.ConstraintFunc = func(ctx validation.Context) []validation.ConstraintViolation {
	if !validation.IsEmpty(ctx.Value().Node) {
		return []validation.ConstraintViolation{
			ctx.Violation("a value must not be provided", nil),
		}
	}
	return nil
}

Empty ...

View Source
var Nil validation.ConstraintFunc = func(ctx validation.Context) []validation.ConstraintViolation {
	rval := validation.UnwrapValue(ctx.Value().Node)
	if validation.IsNillable(rval) && !rval.IsNil() {
		return []validation.ConstraintViolation{
			ctx.Violation("value must be nil", nil),
		}
	}

	return nil
}

Nil ...

View Source
var NotNil validation.ConstraintFunc = func(ctx validation.Context) []validation.ConstraintViolation {
	rval := validation.UnwrapValue(ctx.Value().Node)
	if validation.IsNillable(rval) && rval.IsNil() {
		return []validation.ConstraintViolation{
			ctx.Violation("value must not be nil", nil),
		}
	}

	return nil
}

NotNil ...

View Source
var Required validation.ConstraintFunc = func(ctx validation.Context) []validation.ConstraintViolation {
	rval := validation.UnwrapValue(ctx.Value().Node)
	if validation.IsEmpty(rval) {
		return []validation.ConstraintViolation{
			ctx.Violation("a value is required", nil),
		}
	}
	return nil
}

Required ...

Functions

func AtLeastNRequired

func AtLeastNRequired(n int, fields ...string) validation.ConstraintFunc

AtLeastNRequired ...

func AtMostNRequired

func AtMostNRequired(n int, fields ...string) validation.ConstraintFunc

AtMostNRequired ...

func Details added in v0.2.2

func Details(c validation.Constraint, msg string, details ...any) validation.ConstraintFunc

Details allows you to provide a custom violation message and details for a constraint. This can be used to provide purpose-specific messages and details for constraints, as opposed to the generic messaging that constraints typically provide.

func Equals

func Equals(value any) validation.ConstraintFunc

Equals ...

func ExactlyNRequired

func ExactlyNRequired(n int, fields ...string) validation.ConstraintFunc

ExactlyNRequired ...

func Kind

func Kind(allowed ...reflect.Kind) validation.ConstraintFunc

Kind ...

func Length

func Length(length int) validation.ConstraintFunc

Length ...

func Max

func Max(max float64) validation.ConstraintFunc

Max ...

func MaxLength

func MaxLength(max int) validation.ConstraintFunc

MaxLength ...

func Min

func Min(min float64) validation.ConstraintFunc

Min ...

func MinLength

func MinLength(min int) validation.ConstraintFunc

MinLength ...

func MutuallyExclusive

func MutuallyExclusive(fields ...string) validation.ConstraintFunc

MutuallyExclusive ... TODO: Support maps.

func MutuallyInclusive

func MutuallyInclusive(fields ...string) validation.ConstraintFunc

MutuallyInclusive ... TODO: Support maps.

func NoneOf

func NoneOf(disallowed ...any) validation.ConstraintFunc

NoneOf ...

func NotEquals

func NotEquals(value any) validation.ConstraintFunc

NotEquals ...

func OneOf

func OneOf(allowed ...any) validation.ConstraintFunc

OneOf ...

func OneOfKeys added in v0.1.4

func OneOfKeys(keys ...any) validation.ConstraintFunc

OneOfKeys ...

func Regexp

func Regexp(pattern *regexp.Regexp) validation.ConstraintFunc

Regexp ...

func TimeAfter

func TimeAfter(after time.Time) validation.ConstraintFunc

TimeAfter ...

func TimeBefore

func TimeBefore(before time.Time) validation.ConstraintFunc

TimeBefore ...

func ValueFunc added in v0.4.0

func ValueFunc(fn ValueFuncFunc, kinds ...reflect.Kind) validation.ConstraintFunc

ValueFunc is a helper-constraint that makes it easier to define custom constraints by just taking an unwrapped value after verifying it's the correct kind.

Types

type ValueFuncFunc added in v0.4.0

type ValueFuncFunc func(ctx validation.Context, rval reflect.Value) []validation.ConstraintViolation

ValueFuncFunc is a function used by ValueFunc to perform validation.

Jump to

Keyboard shortcuts

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