Documentation
¶
Overview ¶
Package validator provides a small, generic business-rule validator for the service layer — the below-transport-boundary complement to the proto/request validation performed at the transport edge (connect ValidateInterceptor). It carries no backends and needs no Kind/factory: it is a pure composition mechanism over caller-supplied rules.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Ensure ¶
func Ensure(dtos ...interfaces.Validatable) error
Ensure runs Validate() on each DTO in order and returns the first coded violation, or nil when all pass. It is the hand-written-service chokepoint: call it at a service or workflow entry to enforce a DTO's self-validation — the generated Validate() composed with its optional domainRules() hook — below the transport edge, so non-edge writers (seed, connector sync, internal RPC) and server-injected fields are validated as CodeInvalidInput just like edge requests.
A nil entry — an untyped nil OR a typed nil pointer (e.g. a nil *SomeDTO passed as an optional Validatable) — is skipped, so an unset optional DTO never panics in Validate(). Callers that must aggregate every violation (e.g. a bulk request reporting all offenders in one response) run each DTO's Validate() themselves rather than short-circuiting here.
Types ¶
type Rule ¶
Rule validates one aspect of a *T, returning a non-nil error on violation and nil when satisfied. Rules should return a core/errors.AppError carrying CodeInvalidInput (ARCHITECTURE.md#error-codes) so the failure classifies and maps to a 400 / InvalidArgument at the transport edge.
type Validator ¶
type Validator[T any] struct { // contains filtered or unexported fields }
Validator runs an ordered set of Rules against a *T, short-circuiting on the first violation. The zero Validator (no rules) accepts everything.