validation

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package validation validates struct tags without framework dependencies.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApplicationError

func ApplicationError(err error) *app.AppError

ApplicationError converts field failures into approved public validation details, preserving the original cause.

func DecodeJSON

func DecodeJSON(w http.ResponseWriter, r *http.Request, dst any, maxBytes int64) error

DecodeJSON consumes and closes one bounded JSON request body, rejects unknown fields/trailing documents, then validates dst.

func Struct

func Struct(v any) error

Struct validates nested struct fields and collects safe field-level errors.

Types

type Errors

type Errors []FieldError

Errors collects field-level validation failures.

func (Errors) Error

func (e Errors) Error() string

Error returns a diagnostic error description.

type FieldError

type FieldError struct {
	Field   string `json:"field"`
	Rule    string `json:"rule"`
	Message string `json:"message"`
}

FieldError describes a safe field-level validation failure.

type Validator

type Validator struct{ Rules map[string]func(any) bool }

Validator applies built-in rules and optional application validators.

func (Validator) Struct

func (v Validator) Struct(x any) error

Struct validates nested struct fields and collects safe field-level errors.

Jump to

Keyboard shortcuts

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