validation

package
v2.8.0 Latest Latest
Warning

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

Go to latest
Published: Jan 1, 2026 License: GPL-3.0 Imports: 10 Imported by: 0

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

View Source
var (
	ErrMissingParams = errors.New("missing params")
	ErrInvalidParams = errors.New("invalid params")
)

Common validation errors.

View Source
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

func ValidateRegexPattern(pattern string) error

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

func NewContext(launcherIDs []string) *Context

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.

func (*Error) Error

func (e *Error) Error() string

type FieldError

type FieldError struct {
	Field   string
	Tag     string
	Value   any
	Message string
}

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.

func (*Validator) Validate

func (v *Validator) Validate(params any) error

Validate validates a struct and returns a formatted error if validation fails.

func (*Validator) ValidateCtx

func (v *Validator) ValidateCtx(ctx context.Context, params any, vctx *Context) error

ValidateCtx validates a struct with context and returns a formatted error.

Jump to

Keyboard shortcuts

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