validation

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package validation provides synchronous pre-upload validation. Validation runs BEFORE any file is stored to the driver, so a failed validation rejects the upload at the caller boundary (400 Bad Request).

The workflow's validate: block is translated into a ValidationRequest and passed through the Validator chain.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsValidationError

func IsValidationError(err error) bool

IsValidationError reports whether err (or any in its chain) is an ErrValidation.

Types

type CheckRegistry

type CheckRegistry interface {
	Find(uses string) CheckValidator
}

CheckRegistry maps step "uses" strings to CheckValidator implementations.

type CheckValidator

type CheckValidator interface {
	Validate(ctx context.Context, check *models.WorkflowValidateCheck, req *ValidationRequest) error
}

CheckValidator is a named validation check that can be registered and invoked by the validation framework.

type ErrValidation

type ErrValidation struct {
	Field   string // e.g. "size", "content_type", "check:check-duration"
	Message string
}

ErrValidation is the base type for all validation failures. Callers can test with errors.As or errors.Is.

func (*ErrValidation) Error

func (e *ErrValidation) Error() string

type ValidationRequest

type ValidationRequest struct {
	// Reader provides the file bytes. The validator may read it to detect
	// content type; it will not be consumed beyond what is necessary for
	// sniffing (at most 512 bytes).
	Reader io.Reader
	// Size is the Content-Length reported by the caller; 0 if unknown.
	Size int64
	// ContentType is the declared MIME type; may be empty.
	ContentType string
}

ValidationRequest carries the data to be validated.

type Validator

type Validator interface {
	Validate(ctx context.Context, req *ValidationRequest) error
}

Validator checks a ValidationRequest against one or more rules. Multiple Validators are chained via Chain.

func Chain

func Chain(validators ...Validator) Validator

Chain returns a Validator that runs each validator in order. The first error stops execution.

func ContentTypeValidator

func ContentTypeValidator(allowed []string) Validator

ContentTypeValidator rejects files whose content type does not match any of the allowed patterns. If the request ContentType is empty, up to 512 bytes are sniffed from the reader.

func FromWorkflowValidate

func FromWorkflowValidate(v *models.WorkflowValidate, registry CheckRegistry) Validator

FromWorkflowValidate builds a Validator from a WorkflowValidate block. External step checks (uses: video.probe, etc.) are looked up in registry. If registry is nil the step checks are skipped with a warning.

func MaxSizeValidator

func MaxSizeValidator(maxBytes int64) Validator

MaxSizeValidator rejects files exceeding maxBytes.

func MinSizeValidator

func MinSizeValidator(minBytes int64) Validator

MinSizeValidator rejects files smaller than minBytes.

type ValidatorFunc

type ValidatorFunc func(ctx context.Context, req *ValidationRequest) error

ValidatorFunc adapts a plain function to the Validator interface.

func (ValidatorFunc) Validate

func (f ValidatorFunc) Validate(ctx context.Context, req *ValidationRequest) error

Jump to

Keyboard shortcuts

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