validation

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2026 License: AGPL-3.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ErrorMessageFunc

type ErrorMessageFunc func(field string, param string) string

ErrorMessageFunc is a function that generates an error message for a validation error. It receives the field name and the validation parameter (if any).

type ValidatorService

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

ValidatorService wraps the validator.Validate instance and provides custom validation functionality with user-friendly error messages.

func NewValidatorService

func NewValidatorService() *ValidatorService

NewValidatorService creates a new validation service with default validators.

func (*ValidatorService) RegisterErrorMessage

func (vs *ValidatorService) RegisterErrorMessage(tag string, errorMsgFn ErrorMessageFunc)

RegisterErrorMessage registers or updates an error message for a validation tag. This is useful when you want to customize error messages for built-in validators.

func (*ValidatorService) RegisterValidator

func (vs *ValidatorService) RegisterValidator(tag string, validatorFn validator.Func, errorMsgFn ErrorMessageFunc) error

RegisterValidator registers a custom validator function with its error message. tag: the validation tag to use in struct tags (e.g., "stellar_xdr") validatorFn: the validation function errorMsgFn: the error message function (receives field name and param)

func (*ValidatorService) Validate

func (vs *ValidatorService) Validate(data interface{}) (map[string]string, error)

Validate validates a struct and returns field-specific error messages. Returns a map where keys are field names (in snake_case) and values are error messages.

Jump to

Keyboard shortcuts

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