validation

package
v2.10.0 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2026 License: GPL-3.0 Imports: 10 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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