Documentation
¶
Overview ¶
Package validation provides validation for API request parameters using go-playground/validator with custom validators for Zaparoo-specific types.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrMissingParams = errors.New("missing params") ErrInvalidParams = errors.New("invalid params") )
Common validation errors.
var DefaultValidator = NewValidator()
DefaultValidator is a shared validator instance for API use.
Functions ¶
func ValidateAndUnmarshal ¶
func ValidateAndUnmarshal[T any](params json.RawMessage, dest *T) error
ValidateAndUnmarshal unmarshals JSON params and validates them. Returns ErrMissingParams if params is empty, ErrInvalidParams if unmarshal fails, or an Error if validation fails.
func ValidateAndUnmarshalCtx ¶
func ValidateAndUnmarshalCtx[T any](ctx context.Context, params json.RawMessage, dest *T, vctx *Context) error
ValidateAndUnmarshalCtx unmarshals JSON params and validates them with context.
func ValidateRegexPattern ¶
ValidateRegexPattern validates that a regex pattern compiles successfully. This is for cases where we need the actual error message from regex compilation.
Types ¶
type Context ¶
type Context struct {
LauncherIDs []string
}
Context provides runtime context for validation.
func NewContext ¶
NewContext creates a Context from a list of launcher IDs.
type Error ¶
type Error struct {
Fields []FieldError
}
Error wraps validation errors with formatted messages.
func NewError ¶
func NewError(errs validator.ValidationErrors) *Error
NewError creates an Error from validator.ValidationErrors.
type FieldError ¶
FieldError represents a single field validation error.
type Validator ¶
type Validator struct {
// contains filtered or unexported fields
}
Validator handles validation of API parameters.
func NewValidator ¶
func NewValidator() *Validator
NewValidator creates a new Validator with registered custom validators.