constraints

package
v0.0.0-...-d4025e8 Latest Latest
Warning

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

Go to latest
Published: Dec 23, 2019 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var BuiltIn = map[string]valley.ConstraintGenerator{
	"github.com/seeruk/valley/validation/constraints.AnyNRequired":      anyNRequiredGenerator,
	"github.com/seeruk/valley/validation/constraints.DeepEquals":        deepEqualsGenerator,
	"github.com/seeruk/valley/validation/constraints.Equals":            equalsGenerator,
	"github.com/seeruk/valley/validation/constraints.ExactlyNRequired":  exactlyNRequiredGenerator,
	"github.com/seeruk/valley/validation/constraints.Length":            lengthGenerator(lengthExact),
	"github.com/seeruk/valley/validation/constraints.Max":               minMaxGenerator(max),
	"github.com/seeruk/valley/validation/constraints.MaxLength":         lengthGenerator(lengthMax),
	"github.com/seeruk/valley/validation/constraints.Min":               minMaxGenerator(min),
	"github.com/seeruk/valley/validation/constraints.MinLength":         lengthGenerator(lengthMin),
	"github.com/seeruk/valley/validation/constraints.MutuallyExclusive": mutuallyExclusiveGenerator,
	"github.com/seeruk/valley/validation/constraints.MutuallyInclusive": mutuallyInclusiveGenerator,
	"github.com/seeruk/valley/validation/constraints.Nil":               nilGenerator,
	"github.com/seeruk/valley/validation/constraints.NotEquals":         notEqualsGenerator,
	"github.com/seeruk/valley/validation/constraints.NotNil":            notNilGenerator,
	"github.com/seeruk/valley/validation/constraints.OneOf":             oneOfGenerator,
	"github.com/seeruk/valley/validation/constraints.Predicate":         predicateGenerator,
	"github.com/seeruk/valley/validation/constraints.Regexp":            regexpGenerator,
	"github.com/seeruk/valley/validation/constraints.RegexpString":      regexpStringGenerator,
	"github.com/seeruk/valley/validation/constraints.Required":          requiredGenerator,
	"github.com/seeruk/valley/validation/constraints.TimeAfter":         timeGenerator(timeAfter),
	"github.com/seeruk/valley/validation/constraints.TimeBefore":        timeGenerator(timeBefore),
	"github.com/seeruk/valley/validation/constraints.TimeStringAfter":   timeStringGenerator(timeStringAfter),
	"github.com/seeruk/valley/validation/constraints.TimeStringBefore":  timeStringGenerator(timeStringBefore),
	"github.com/seeruk/valley/validation/constraints.Valid":             validGenerator,
}

BuiltIn is a map of all of the built-in validation constraints provided by Valley. This is exposed so that custom code generators can build on the set of built-in rules, and also use the logic exposed. It's tricky to otherwise make Valley extensible.

View Source
var (
	// ErrTypeWarning is an error returned when a constraint might have been used on an unsupported
	// type. Some constraints may choose to be permissive and continue anyway. This error will only
	// result in a warning being printed. It's up to the constraint if it halts constraint
	// generation (i.e. if that constraint will produce no code, but execution will continue...)
	ErrTypeWarning = errors.New("type used may not produce valid code (is it a custom type?)")
)

Functions

func AnyNRequired

func AnyNRequired(n int, fields ...interface{}) valley.Constraint

AnyNRequired ...

func CollectExprImports

func CollectExprImports(ctx valley.Context, expr ast.Expr) []valley.Import

CollectExprImports looks for things that appear to be imports in the given expression, and attempts to find matching imports in the given valley.Context, returning any that are found.

func DeepEquals

func DeepEquals(_ interface{}) valley.Constraint

DeepEquals ...

func Equals

func Equals(_ interface{}) valley.Constraint

Equals ...

func ExactlyNRequired

func ExactlyNRequired(n int, fields ...interface{}) valley.Constraint

ExactlyNRequired ...

func GenerateEmptinessPredicate

func GenerateEmptinessPredicate(varName string, fieldType ast.Expr) (string, []valley.Import)

GenerateEmptinessPredicate ...

func GenerateStandardConstraint

func GenerateStandardConstraint(ctx valley.Context, predicate, message string, details map[string]interface{}) string

GenerateStandardConstraint ...

func GenerateVariableName

func GenerateVariableName(ctx valley.Context) string

GenerateVariableName ...

func Length

func Length(length int) valley.Constraint

Length ...

func Max

func Max(max int) valley.Constraint

Max ...

func MaxLength

func MaxLength(max int) valley.Constraint

MaxLength ...

func Min

func Min(min int) valley.Constraint

Min ...

func MinLength

func MinLength(min int) valley.Constraint

MinLength ...

func MutuallyExclusive

func MutuallyExclusive(fields ...interface{}) valley.Constraint

MutuallyExclusive ...

func MutuallyInclusive

func MutuallyInclusive(fields ...interface{}) valley.Constraint

MutuallyInclusive ...

func Nil

func Nil() valley.Constraint

Nil ...

func NotEquals

func NotEquals(_ interface{}) valley.Constraint

NotEquals ...

func NotNil

func NotNil() valley.Constraint

NotNil ...

func OneOf

func OneOf(values ...interface{}) valley.Constraint

OneOf ...

func Predicate

func Predicate(predicate bool, message string) valley.Constraint

Predicate ...

func Regexp

func Regexp(regexp *regexp.Regexp) valley.Constraint

Regexp ...

func RegexpString

func RegexpString(regexp string) valley.Constraint

Regexp ...

func Required

func Required() valley.Constraint

Required ...

func SprintNode

func SprintNode(fileSet *token.FileSet, node ast.Node) (string, error)

SprintNode uses the go/printer package to print an AST node, returning it as a string.

func TimeAfter

func TimeAfter(after time.Time) valley.Constraint

TimeAfter ...

func TimeBefore

func TimeBefore(before time.Time) valley.Constraint

TimeBefore ...

func TimeStringAfter

func TimeStringAfter(after string) valley.Constraint

TimeStringAfter ...

func TimeStringBefore

func TimeStringBefore(before string) valley.Constraint

TimeStringBefore ...

func Valid

func Valid() valley.Constraint

Valid ...

Types

This section is empty.

Jump to

Keyboard shortcuts

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