validation

package
v1.13.0-beta.1 Latest Latest
Warning

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

Go to latest
Published: May 29, 2025 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package validation provides comprehensive input validation functions and utilities. It includes struct validation, field validation, and custom validator registration.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Email

func Email(email string, fieldName string) error

Email validates that the provided email string matches a valid email format

func InRange

func InRange(value, minVal, maxVal int64, fieldName string) error

InRange validates that a number is within a range

func Matches

func Matches(value, pattern, fieldName string) error

Matches validates that a string matches a regex pattern

func MaxLength

func MaxLength(value string, maxLength int, fieldName string) error

MaxLength validates maximum string length

func MinLength

func MinLength(value string, minLength int, fieldName string) error

MinLength validates minimum string length

func OneOf

func OneOf(value string, allowed []string, fieldName string) error

OneOf validates that a value is one of the allowed values

func RegisterCustomValidator

func RegisterCustomValidator(name string, fn func(any) error) error

RegisterCustomValidator registers a custom validator function

func Required

func Required(value any, fieldName string) error

Required validates that a value is not empty/zero

func URL

func URL(urlStr string, fieldName string) error

URL validates URL format

func UUID

func UUID(uuidStr string, fieldName string) error

UUID validates UUID format

Types

type ValidationError

type ValidationError struct {
	Field   string
	Message string
	Value   any
}

ValidationError represents a validation error with field and message details. The type name intentionally matches the package name for clarity in external usage.

func NewValidationError

func NewValidationError(message, field string) ValidationError

NewValidationError creates a new validation error

func ValidateStruct

func ValidateStruct(s any) []ValidationError

ValidateStruct validates a struct based on validate tags

func (ValidationError) Error

func (e ValidationError) Error() string

Error implements the error interface

Jump to

Keyboard shortcuts

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