val

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package val provides struct field validation utilities.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ValidatePassword

func ValidatePassword(password string, errs []string) []string

ValidatePassword validates a password string.

Types

type Error

type Error struct {
	Fields  []error
	Message string
	Type    string
}

Error is a top-level validation error.

func NewError

func NewError(message string) *Error

NewError creates a new validation error.

func (Error) Error

func (e Error) Error() string

func (Error) Messages

func (e Error) Messages() map[string]string

Messages returns a map of field error messages.

type FieldError

type FieldError struct {
	Field   string
	Message string
}

FieldError is a per-field validation error.

func NewFieldError

func NewFieldError(field string, message string) *FieldError

NewFieldError creates a new field error.

func (FieldError) Error

func (f FieldError) Error() string

type StringValidationContext

type StringValidationContext struct {
	IsValid bool
	// contains filtered or unexported fields
}

StringValidationContext provides fluent string validation.

func CheckString

func CheckString(str string) *StringValidationContext

CheckString creates a string validation context.

func (*StringValidationContext) IsPassword

IsPassword validates password requirements.

func (*StringValidationContext) LengthIsGreaterThanOrEqualTo

func (s *StringValidationContext) LengthIsGreaterThanOrEqualTo(n int) *StringValidationContext

LengthIsGreaterThanOrEqualTo validates minimum length.

type Validator

type Validator struct {
	Value reflect.Value
	// contains filtered or unexported fields
}

Validator validates struct fields using registered validation functions.

func New

func New() *Validator

New creates a new Validator.

func (*Validator) Add

Add registers a validation function for the current field.

func (*Validator) Check

func (v *Validator) Check(field string) *Validator

Check sets the current field to be validated.

func (*Validator) Ensure

func (v *Validator) Ensure(fn ValidatorFunction) *Validator

Ensure adds a custom validation function.

func (*Validator) Exec

func (v *Validator) Exec(value interface{}) []error

Exec runs all validation functions and returns any errors.

func (*Validator) Exists

func (v *Validator) Exists() *Validator

Exists validates that the field is not empty.

func (*Validator) IsEmail

func (v *Validator) IsEmail() *Validator

IsEmail validates that the field looks like an email address.

func (*Validator) IsPassword

func (v *Validator) IsPassword() *Validator

IsPassword validates minimum password requirements.

func (*Validator) Matches

func (v *Validator) Matches(strs ...string) *Validator

Matches validates the field matches one of the given strings.

func (*Validator) MinLength

func (v *Validator) MinLength(minLength int) *Validator

MinLength validates minimum string length.

type ValidatorFunction

type ValidatorFunction interface{}

ValidatorFunction is a function that validates a value.

Jump to

Keyboard shortcuts

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