validation

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package validation provides custom validation rules for the application.

Package validation provides custom validation rules for the application.

Index

Constants

This section is empty.

Variables

View Source
var Base64 = validation.By(func(value interface{}) error {
	s, ok := value.(string)
	if !ok {
		return validation.NewError("validation_base64_type", "must be a string")
	}
	if s == "" {
		return nil
	}
	_, err := base64.StdEncoding.DecodeString(s)
	if err != nil {
		return validation.NewError("validation_base64", "must be valid base64-encoded data")
	}
	return nil
})

Base64 validates that a string is valid base64-encoded data.

View Source
var Email = validation.NewStringRuleWithError(
	func(s string) bool {
		return emailRegex.MatchString(s)
	},
	validation.NewError("validation_email_format", "must be a valid email address"),
)

Email validates email format using regex

View Source
var NoWhitespace = validation.NewStringRuleWithError(
	func(s string) bool {
		return s == strings.TrimSpace(s)
	},
	validation.NewError("validation_no_whitespace", "must not contain leading or trailing whitespace"),
)

NoWhitespace validates that string doesn't contain leading/trailing whitespace

View Source
var NotBlank = validation.NewStringRuleWithError(
	func(s string) bool {
		return strings.TrimSpace(s) != ""
	},
	validation.NewError("validation_not_blank", "must not be blank"),
)

NotBlank validates that a string is not empty after trimming whitespace

Functions

func WrapValidationError

func WrapValidationError(err error) error

WrapValidationError wraps validation errors as domain ErrInvalidInput.

Types

type PasswordStrength

type PasswordStrength struct {
	MinLength      int
	RequireUpper   bool
	RequireLower   bool
	RequireNumber  bool
	RequireSpecial bool
}

PasswordStrength validates password meets minimum security requirements.

func (PasswordStrength) Validate

func (p PasswordStrength) Validate(value interface{}) error

Validate checks if the password meets the configured requirements.

Jump to

Keyboard shortcuts

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