Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Constraint ¶
type Constraint interface {
Validate(value any, field string) ValidationError
}
type ParameterizedConstraint ¶ added in v2.9.0
type ParameterizedConstraint interface {
Constraint
WithParams(params map[string]string) (Constraint, error)
}
ParameterizedConstraint is implemented by constraints that accept tag parameters (for example min(value=2)). WithParams returns a NEW constraint configured from the given parameters and must not mutate the receiver; a rule whose parameters cannot be consumed fails closed. A rule that names a parameterized constraint WITHOUT parameters fails closed too — the registered instance is a template for WithParams, never a fallback configuration.
The returned constraint MUST be immutable and safe for concurrent use: the validator constructs it once per distinct (rule name, parameters) pair and then shares that one instance for the rest of the process, across every request and goroutine that reaches the rule. A constraint that accumulates state in Validate, or that retains the params map it was handed, will leak that state between unrelated requests.
WithParams itself may be called concurrently for the same parameters, and only one of the resulting constraints is kept; the others are discarded, so it must have no side effects outside the value it returns. It MUST also be a pure function of its parameters: the validator memoizes its refusals exactly like its successes for the process lifetime, so an outcome that depends on anything but the parameters — a registry still being populated, a config read — freezes whichever answer the first call happened to get.