validator

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package validator provides configuration validation functionality. Includes URL validation, path validation and other security validation features.

Package validator provides data validation functionality. Supports phone number and email format validation, supports phone number formats for multiple countries/regions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ValidateConfigPath

func ValidateConfigPath(path string, allowedDirs []string) (string, error)

ValidateConfigPath validates configuration file path to prevent path traversal attacks

This function validates configuration file path, including: - Checks if path contains path traversal characters (..) - Validates if path is absolute or relative path - Optional: restrict configuration files to be read only from specific directories

Parameters:

  • path: file path to validate
  • allowedDirs: list of allowed directories (optional, if empty then no directory restriction)

Returns:

  • string: normalized absolute path
  • error: returns error if path is invalid or has security risks; otherwise returns nil

func ValidateEmail

func ValidateEmail(email string) bool

ValidateEmail validates email format (stricter validation)

func ValidatePhone

func ValidatePhone(phone string) bool

ValidatePhone validates phone number format (supports multiple countries/regions)

func ValidateRemoteURL

func ValidateRemoteURL(urlStr string) error

ValidateRemoteURL validates remote configuration URL to prevent SSRF attacks

This function performs strict validation on remote configuration URL, including: - Only allows http:// and https:// protocols - Prohibits access to private IP addresses (10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16, 127.0.0.0/8) - Prohibits access to localhost - Validates URL format validity

Parameters:

  • urlStr: URL string to validate

Returns:

  • error: returns error if URL is invalid or has security risks; otherwise returns nil

func ValidateUser

func ValidateUser(phone, email string) error

ValidateUser validates user data

Types

type ValidationError

type ValidationError struct {
	Field   string
	Message string
}

ValidationError validation error

func (*ValidationError) Error

func (e *ValidationError) Error() string

Jump to

Keyboard shortcuts

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