Documentation
¶
Index ¶
- Constants
- Variables
- func Alias(check string) []string
- func NewBetween() func(field *Field, check *Check) (IsValid, error)
- func NewCIDR() func(field *Field, check *Check) (IsValid, error)
- func NewChoice() func(field *Field, check *Check) (IsValid, error)
- func NewContains() func(field *Field, check *Check) (IsValid, error)
- func NewEndsWith() func(field *Field, check *Check) (IsValid, error)
- func NewEqField() func(field *Field, check *Check) (IsValid, error)
- func NewFuture() func(field *Field, check *Check) (IsValid, error)
- func NewGt() func(field *Field, check *Check) (IsValid, error)
- func NewGtField() func(field *Field, check *Check) (IsValid, error)
- func NewGte() func(field *Field, check *Check) (IsValid, error)
- func NewHTTPURL() func(field *Field, check *Check) (IsValid, error)
- func NewHostname() func(field *Field, check *Check) (IsValid, error)
- func NewIP() func(field *Field, check *Check) (IsValid, error)
- func NewIPv4() func(field *Field, check *Check) (IsValid, error)
- func NewIPv6() func(field *Field, check *Check) (IsValid, error)
- func NewJSON() func(field *Field, check *Check) (IsValid, error)
- func NewLt() func(field *Field, check *Check) (IsValid, error)
- func NewLte() func(field *Field, check *Check) (IsValid, error)
- func NewMAC() func(field *Field, check *Check) (IsValid, error)
- func NewMax() func(field *Field, check *Check) (IsValid, error)
- func NewMin() func(field *Field, check *Check) (IsValid, error)
- func NewNeField() func(field *Field, check *Check) (IsValid, error)
- func NewNotContains() func(field *Field, check *Check) (IsValid, error)
- func NewNotRegExprCheck(expr *regexp.Regexp) func(field *Field, check *Check) (IsValid, error)
- func NewPast() func(field *Field, check *Check) (IsValid, error)
- func NewPort() func(field *Field, check *Check) (IsValid, error)
- func NewRegExprCheck(expr *regexp.Regexp) func(field *Field, check *Check) (IsValid, error)
- func NewRegExprCheckWithMinLength(expr *regexp.Regexp, minLen int) func(field *Field, check *Check) (IsValid, error)
- func NewRepeatedRegExprCheck(expr *regexp.Regexp, separator string) func(field *Field, check *Check) (IsValid, error)
- func NewRequiredIf() func(field *Field, check *Check) (IsValid, error)
- func NewRequiredUnless() func(field *Field, check *Check) (IsValid, error)
- func NewRequiredWith() func(field *Field, check *Check) (IsValid, error)
- func NewRequiredWithout() func(field *Field, check *Check) (IsValid, error)
- func NewSemver() func(field *Field, check *Check) (IsValid, error)
- func NewSlug() func(field *Field, check *Check) (IsValid, error)
- func NewStartsWith() func(field *Field, check *Check) (IsValid, error)
- func NewURI() func(field *Field, check *Check) (IsValid, error)
- func NewURL() func(field *Field, check *Check) (IsValid, error)
- func NewUUIDv7() func(field *Field, check *Check) (IsValid, error)
- func Register(check string, fn NewIsValid)
- func RegisterAlias(check string, checks ...string)
- func RegisterWithDependencies(name string, factory NewIsValid, dependencies DependencyResolver)
- func SessionContext(ctx context.Context, session *Session) context.Context
- type CanUseMarkerProvider
- type Check
- type Checks
- type Choice
- type DependencyResolver
- type Field
- type FieldCheck
- type IsValid
- type NewIsValid
- type Numeric
- type Option
- func WithCanUseMarkerProvider(provider CanUseMarkerProvider) Option
- func WithDeferredFields(deferred func(string) bool) Option
- func WithFieldFilter(filter func(string) bool) Option
- func WithPath(path *Path) Option
- func WithPreservePointer(flag bool) Option
- func WithSetMarker() Option
- func WithShallow(flag bool) Option
- type Options
- type Path
- type PathKind
- type Prepared
- type RegExprCheck
- type Service
- type Session
- type Tag
- type Validation
- type Violation
- type Zeroable
Constants ¶
const ( //PathKindRoot defines root path kind PathKindRoot = PathKind(iota) //PathKinField defines field path kind PathKinField //PathKindKey defines key path kind PathKindKey //PathKindIndex defines index path kind PathKindIndex )
Variables ¶
var SessionKey string
SessionKey represents a session key
Functions ¶
func NewBetween ¶ added in v0.3.4
func NewContains ¶ added in v0.3.4
func NewEndsWith ¶ added in v0.3.4
func NewEqField ¶ added in v0.3.4
func NewGtField ¶ added in v0.3.4
func NewHTTPURL ¶ added in v0.3.4
func NewHostname ¶ added in v0.3.4
func NewNeField ¶ added in v0.3.4
func NewNotContains ¶ added in v0.3.4
func NewNotRegExprCheck ¶
func NewRegExprCheck ¶
NewRegExprCheck creates a regexpr based validation check
func NewRegExprCheckWithMinLength ¶
func NewRegExprCheckWithMinLength(expr *regexp.Regexp, minLen int) func(field *Field, check *Check) (IsValid, error)
NewRegExprCheckWithMinLength creates a regexpr based validation check with min Length
func NewRepeatedRegExprCheck ¶
func NewRequiredIf ¶ added in v0.3.4
func NewRequiredUnless ¶ added in v0.3.4
func NewRequiredWith ¶ added in v0.3.4
func NewRequiredWithout ¶ added in v0.3.4
func NewStartsWith ¶ added in v0.3.4
func RegisterAlias ¶
RegisterAlias register tag alias
func RegisterWithDependencies ¶ added in v0.3.4
func RegisterWithDependencies(name string, factory NewIsValid, dependencies DependencyResolver)
RegisterWithDependencies registers a check with explicit availability metadata. An empty dependency list declares self-only; a nil resolver remains opaque. Dependencies are canonical visible sibling names, with self always implicit.
Types ¶
type CanUseMarkerProvider ¶ added in v0.3.0
type CanUseMarkerProvider func(v interface{}) bool
type Checks ¶
type Checks struct {
Type reflect.Type
Fields []*FieldCheck
Slices []*Field
Structs []*Field
SimpleSlices []*Field
// contains filtered or unexported fields
}
Checks represents struct checks
func (*Checks) InputFields ¶ added in v0.3.4
InputFields returns detached canonical names of visible shallow inputs, including unvalidated siblings. Set markers are not validation inputs.
func (*Checks) Prepare ¶ added in v0.3.4
Prepare captures field/rule selection without reading input values, running predicates or recompiling Checks. Explicit WithShallow(true) is required. Marker options require a nonnil FieldFilter that overrides marker coverage.
func (*Checks) ValidateAvailability ¶ added in v0.3.4
ValidateAvailability preflights shallow rule availability without reading any input values or executing predicates. include selects fields; deferred marks temporarily unavailable inputs independently of that selection. Nil deferral retains ordinary validation. Preflight every candidate before executing a batch when their include/deferred callbacks differ.
type DependencyResolver ¶ added in v0.3.4
DependencyResolver declares additional inputs read by a check. Names are visible Go sibling selectors; self is implicit. A non-nil resolver returning an empty list declares self-only. It runs during native plan compilation.
type FieldCheck ¶
FieldCheckPos represents field checks
type NewIsValid ¶
NewIsValid function to create IsValid
func LookupAll ¶
func LookupAll(check string) NewIsValid
LookupAll returns a factory, or nil for unknown, empty or cyclic aliases.
type Option ¶
type Option func(c *Options)
func WithCanUseMarkerProvider ¶ added in v0.3.0
func WithCanUseMarkerProvider(provider CanUseMarkerProvider) Option
WithCanUseMarkerProvider creates with marker provider option
func WithDeferredFields ¶ added in v0.3.4
WithDeferredFields marks temporarily unavailable fields by canonical Go name. Non-nil deferral requires shallow validation and explicit field filtering when marker options are present. Nil retains ordinary complete rule execution.
func WithFieldFilter ¶ added in v0.3.4
WithFieldFilter selects checks by Go selector paths relative to the root. Promoted fields use their visible names; slice indexes, WithPath and skipPath do not affect selection. A non-nil filter overrides marker coverage. Selecting a nested field does not require selecting its traversal containers.
func WithPreservePointer ¶ added in v0.2.3
WithPreservePointer creates with preserve pointer option
func WithSetMarker ¶ added in v0.2.1
func WithSetMarker() Option
WithSetMarker creates with marker option
type Path ¶
type Path struct {
Kind PathKind `json:",omitempty"`
Path *Path `json:",omitempty"`
Name string `json:",omitempty"`
Index int `json:",omitempty"`
Key interface{} `json:",omitempty"`
}
Path represents an arbitrary data structure path
type Prepared ¶ added in v0.3.4
type Prepared struct {
// contains filtered or unexported fields
}
Prepared retains one exact compiled shallow plan and immutable rule choices. It is reusable; predicates and input values remain the caller's concurrency responsibility. Shared compiled Checks and descriptors must remain read-only.
func (*Prepared) Validate ¶ added in v0.3.4
func (p *Prepared) Validate(ctx context.Context, value interface{}) (*Validation, error)
Validate executes the exact Checks and decisions captured by Prepare. Values must have the compiled struct type (optionally through pointers or a single root slice). Type mismatches, including wrong typed nils, fail before access.
type RegExprCheck ¶
type RegExprCheck struct {
// contains filtered or unexported fields
}
func (*RegExprCheck) IsValidString ¶
func (r *RegExprCheck) IsValidString(ctx context.Context, value interface{}) (bool, error)
func (*RegExprCheck) IsValidStringPtr ¶
func (r *RegExprCheck) IsValidStringPtr(ctx context.Context, value interface{}) (bool, error)
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service represents a service
type Validation ¶
func (*Validation) AddViolation ¶ added in v0.1.3
func (v *Validation) AddViolation(field string, value interface{}, check string, msg string)
func (*Validation) Error ¶
func (e *Validation) Error() string
func (*Validation) String ¶
func (e *Validation) String() string