Documentation
¶
Overview ¶
Package validate exposes the struct-tag constraint helper used by Den.
Den runs Document automatically on every Insert and Update — there is no opt-in option, and there is no way to bypass tag-level constraints from inside Den. Call Document directly only at boundaries before the doc reaches Den (typical use: HTTP handlers that want to reject bad input before opening a database transaction). The returned *Errors mirrors what Den's write path would have produced.
The struct-tag syntax follows go-playground/validator/v10:
type Product struct {
document.Base
Name string `json:"name" validate:"required,min=3"`
Email string `json:"email" validate:"required,email"`
Price float64 `json:"price" validate:"required,min=0"`
}
Index ¶
Constants ¶
This section is empty.
Variables ¶
var DefaultValidator = validator.New()
DefaultValidator is the singleton go-playground validator instance used by Struct and (internally) by Den's write path. Exposed so consumers that need to register custom validation functions can do so once for both surfaces.
Functions ¶
func Document ¶ added in v0.12.0
Document validates doc against its `validate` struct tags using DefaultValidator. Returns nil on success, *Errors on validation failure, or a raw error for malformed input (e.g. a nil pointer).
The parameter type is the marker interface every Den document type satisfies by embedding document.Base, so attempts to validate arbitrary non-document structs fail at compile time — use go-playground/validator/v10 directly for that case.
Den's write path calls Document automatically; this entry point is for validating outside the Den boundary (HTTP handlers, form parsers, pre-save checks).
Types ¶
type Errors ¶
type Errors struct {
Fields []FieldError
}
Errors holds all field-level validation failures.