Documentation ¶
Index ¶
- Variables
- func AnyNRequired(n int, fields ...interface{}) valley.Constraint
- func CollectExprImports(ctx valley.Context, expr ast.Expr) []valley.Import
- func DeepEquals(_ interface{}) valley.Constraint
- func Equals(_ interface{}) valley.Constraint
- func ExactlyNRequired(n int, fields ...interface{}) valley.Constraint
- func GenerateEmptinessPredicate(varName string, fieldType ast.Expr) (string, []valley.Import)
- func GenerateStandardConstraint(ctx valley.Context, predicate, message string, details map[string]interface{}) string
- func GenerateVariableName(ctx valley.Context) string
- func Length(length int) valley.Constraint
- func Max(max int) valley.Constraint
- func MaxLength(max int) valley.Constraint
- func Min(min int) valley.Constraint
- func MinLength(min int) valley.Constraint
- func MutuallyExclusive(fields ...interface{}) valley.Constraint
- func MutuallyInclusive(fields ...interface{}) valley.Constraint
- func Nil() valley.Constraint
- func NotEquals(_ interface{}) valley.Constraint
- func NotNil() valley.Constraint
- func OneOf(values ...interface{}) valley.Constraint
- func Predicate(predicate bool, message string) valley.Constraint
- func Regexp(regexp *regexp.Regexp) valley.Constraint
- func RegexpString(regexp string) valley.Constraint
- func Required() valley.Constraint
- func SprintNode(fileSet *token.FileSet, node ast.Node) (string, error)
- func TimeAfter(after time.Time) valley.Constraint
- func TimeBefore(before time.Time) valley.Constraint
- func TimeStringAfter(after string) valley.Constraint
- func TimeStringBefore(before string) valley.Constraint
- func Valid() valley.Constraint
Constants ¶
This section is empty.
Variables ¶
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.
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 ¶
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 ExactlyNRequired ¶
func ExactlyNRequired(n int, fields ...interface{}) valley.Constraint
ExactlyNRequired ...
func GenerateEmptinessPredicate ¶
GenerateEmptinessPredicate ...
func GenerateStandardConstraint ¶
func GenerateStandardConstraint(ctx valley.Context, predicate, message string, details map[string]interface{}) string
GenerateStandardConstraint ...
func GenerateVariableName ¶
GenerateVariableName ...
func MutuallyExclusive ¶
func MutuallyExclusive(fields ...interface{}) valley.Constraint
MutuallyExclusive ...
func MutuallyInclusive ¶
func MutuallyInclusive(fields ...interface{}) valley.Constraint
MutuallyInclusive ...
func SprintNode ¶
SprintNode uses the go/printer package to print an AST node, returning it as a string.
Types ¶
This section is empty.