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: 0

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