validate

package
v0.11.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 3, 2026 License: MIT Imports: 5 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ValidateStruct

func ValidateStruct(doc any) error

ValidateStruct validates a struct using its `validate` struct tags. Returns nil if valid, *Errors if validation fails, or an error for invalid input (e.g. nil).

func WithValidation

func WithValidation() den.Option

WithValidation returns a den.Option that enables struct tag validation using go-playground/validator. Documents with `validate:"..."` struct tags are validated automatically before insert and update operations.

Types

type Errors

type Errors struct {
	Fields []FieldError
}

Errors holds all field-level validation failures.

func (*Errors) Error

func (e *Errors) Error() string

type FieldError

type FieldError struct {
	Field string // struct field name
	Tag   string // validation tag that failed (e.g. "required", "min")
	Value any    // actual value
	Param string // tag parameter (e.g. "3" for min=3)
}

FieldError describes a single field that failed validation.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL