Documentation
¶
Index ¶
- func AutoValidate[Req, Res any](b *action.Builder[Req, Res]) *action.Builder[Req, Res]
- func CompileWithTimeout(pattern string, timeout time.Duration) *regexp.Regexp
- func FromValidatorError(err error) *xerr.AppError
- func Hook() action.AnyHook
- func IsValidEmail(email string) bool
- func IsValidUUID(id string) bool
- func Map(ctx context.Context, data, rules map[string]any) error
- func RegisterCustom(tag string, fn validator.FuncCtx)
- func RegisterType(fn validator.CustomTypeFunc, types ...any)
- func Struct(ctx context.Context, value any) error
- func TrimStringFields(value any)
- func ValidateAction[T any](name string) *action.BuiltAction[T, T]
- func Var(ctx context.Context, value any, rule string) error
- type Validatable
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AutoValidate ¶
AutoValidate wires Kernel's .Validate(...) builder contract directly to validation.Struct, mapping validator/v10 errors into clean xerr.ValidationDetails.
func CompileWithTimeout ¶
CompileWithTimeout prevents ReDoS attacks on dynamic patterns.
func FromValidatorError ¶
FromValidatorError maps validator/v10 field errors to Nexss structured details with short, human-readable messages.
Each ValidationDetail carries:
- Field: the JSON name of the failing field
- Validation: the raw validator tag (e.g. "oneof", "min")
- Value: a short phrase suitable for a per-field error line, written the way a user would describe the problem
The Validation tag is preserved verbatim so callers that branch on it (metrics, i18n, dashboards) keep working unchanged. Only Value is humanized.
func Hook ¶ added in v0.2.0
Hook returns a stateless validation hook suitable for action.Library.Hooks. The OnBuild predicate drops the hook from every action whose Req type carries no `validate:` tags and does not implement Validatable — such actions pay zero cost in Do().
Usage:
action.MustNewRegistry(action.Library{
Name: "myapp",
Actions: myActions,
Hooks: []action.AnyHook{validation.Hook()},
})
func IsValidEmail ¶
func IsValidUUID ¶
func Map ¶ added in v0.3.0
Map validates a runtime map against per-key rule strings. Keys missing from rules are ignored. A nil or empty rules map is a no-op.
Internally each key is validated with Var so the rules syntax is identical to struct tags. The Field component of each returned ValidationDetail is set to the map key.
func RegisterCustom ¶
RegisterCustom registers context-aware validation rules safely at cold-path init. Panics if the tag is invalid or already registered: both are programmer errors.
func RegisterType ¶
func RegisterType(fn validator.CustomTypeFunc, types ...any)
RegisterType registers custom type handlers safely at cold-path init.
func Struct ¶
Struct validates exported fields using `validate:"..."` tags. Automatically trims whitespace, evaluates tags, and calls Validatable.Validate() if implemented.
func TrimStringFields ¶
func TrimStringFields(value any)
TrimStringFields recurses through exported string fields in structs, pointers, and slices, trimming leading and trailing whitespace in-place.
func ValidateAction ¶
func ValidateAction[T any](name string) *action.BuiltAction[T, T]
ValidateAction creates an identity action that validates T using validate tags.
Types ¶
type Validatable ¶
type Validatable interface {
Validate() error
}
Validatable allows structs to execute custom semantic validation logic after tag validation passes. Implementations must be safe for concurrent use.