validation

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2026 License: MIT Imports: 5 Imported by: ? modules, 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 gin-kit validation implementation support.

Index

Constants

This section is empty.

Variables

View Source
var Default = New()

Default is safe for concurrent validation after application startup.

Functions

This section is empty.

Types

type Context

type Context struct {
	// Field store data used by this type.
	Field string
	// Rule store data used by this type.
	Rule string
	// Parameter store data used by this type.
	Parameter string
}

Context is supplied to message translators.

type Errors

type Errors struct {
	// Fields store data used by this type.
	Fields map[string][]FieldError `json:"fields"`
}

Errors groups failures by their JSON field path.

func (*Errors) Error

func (e *Errors) Error() string

Error performs this package operation.

type FieldError

type FieldError struct {
	// Rule store data used by this type.
	Rule string `json:"rule"`
	// Message store data used by this type.
	Message string `json:"message"`
	// Parameters store data used by this type.
	Parameters map[string]string `json:"parameters"`
}

FieldError describes one failed validation rule without exposing the submitted value.

type Translator

type Translator func(Context) string

Translator converts a failed rule into a public, human-readable message.

type Validator

type Validator struct {
	// contains filtered or unexported fields
}

Validator is an explicit wrapper around go-playground/validator.

func New

func New() *Validator

New creates a validator which reports JSON/form field names and English messages.

func (*Validator) RegisterMessage

func (v *Validator) RegisterMessage(rule, message string)

RegisterMessage overrides a message for a rule. The placeholders {field} and {parameter} are expanded when the error is rendered.

func (*Validator) RegisterRule

func (v *Validator) RegisterRule(name string, fn validator.Func) error

RegisterRule registers an application-specific validation tag.

func (*Validator) SetTranslator

func (v *Validator) SetTranslator(translator Translator)

SetTranslator replaces the default English translator.

func (*Validator) Struct

func (v *Validator) Struct(value any) error

Struct validates a request DTO and returns nil or structured field failures.

Jump to

Keyboard shortcuts

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