validation

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2025 License: MIT Imports: 9 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type EnhancedValidator

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

EnhancedValidator provides comprehensive input validation with security features

func NewEnhancedValidator

func NewEnhancedValidator(config ValidationConfig, logger *logrus.Logger) *EnhancedValidator

NewEnhancedValidator creates a new enhanced validator

func (*EnhancedValidator) Close

func (ev *EnhancedValidator) Close() error

Close closes the validator

func (*EnhancedValidator) ValidateEmail

func (ev *EnhancedValidator) ValidateEmail(email string) *ValidationResult

ValidateEmail validates an email address with enhanced checks

func (*EnhancedValidator) ValidateString

func (ev *EnhancedValidator) ValidateString(value string, rules ...string) *ValidationResult

ValidateString validates a string with comprehensive security checks

func (*EnhancedValidator) ValidateStruct

func (ev *EnhancedValidator) ValidateStruct(s interface{}) *ValidationResult

ValidateStruct validates a struct with comprehensive security checks

func (*EnhancedValidator) ValidateURL

func (ev *EnhancedValidator) ValidateURL(urlStr string) *ValidationResult

ValidateURL validates a URL with security checks

type ValidationConfig

type ValidationConfig struct {
	EnableSQLInjectionCheck bool     `json:"enable_sql_injection_check"`
	EnableXSSCheck          bool     `json:"enable_xss_check"`
	EnableCSRFCheck         bool     `json:"enable_csrf_check"`
	MaxStringLength         int      `json:"max_string_length"`
	AllowedFileTypes        []string `json:"allowed_file_types"`
	MaxFileSize             int64    `json:"max_file_size"`
	EnableRateLimiting      bool     `json:"enable_rate_limiting"`
}

ValidationConfig holds validation configuration

type ValidationError

type ValidationError struct {
	Field        string                 `json:"field"`
	Value        interface{}            `json:"value,omitempty"`
	Tag          string                 `json:"tag"`
	Message      string                 `json:"message"`
	Severity     ValidationSeverity     `json:"severity"`
	SecurityRisk bool                   `json:"security_risk"`
	Metadata     map[string]interface{} `json:"metadata,omitempty"`
}

ValidationError represents a validation error with additional context

type ValidationResult

type ValidationResult struct {
	IsValid      bool              `json:"is_valid"`
	Errors       []ValidationError `json:"errors,omitempty"`
	Warnings     []ValidationError `json:"warnings,omitempty"`
	SecurityRisk bool              `json:"security_risk"`
	Score        int               `json:"score"` // 0-100, higher is better
}

ValidationResult contains the result of validation

type ValidationSeverity

type ValidationSeverity string

ValidationSeverity indicates the severity of a validation error

const (
	SeverityLow      ValidationSeverity = "low"
	SeverityMedium   ValidationSeverity = "medium"
	SeverityHigh     ValidationSeverity = "high"
	SeverityCritical ValidationSeverity = "critical"
)

Jump to

Keyboard shortcuts

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