Files
sslh-multiplex-lab/pkg/utils/validation.go
2026-01-29 00:03:02 +00:00

35 lines
679 B
Go

package utils
import (
"fmt"
"net"
"regexp"
)
func ValidateIP(ip string) error {
if net.ParseIP(ip) == nil {
return fmt.Errorf("invalid IP address: %s", ip)
}
return nil
}
func ValidateDomain(domain string) error {
if domain == "" {
return fmt.Errorf("domain cannot be empty")
}
domainRegex := regexp.MustCompile(`^([a-zA-Z0-9]([a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,}$`)
if !domainRegex.MatchString(domain) {
return fmt.Errorf("invalid domain format: %s", domain)
}
return nil
}
func ValidatePort(port int) error {
if port < 1 || port > 65535 {
return fmt.Errorf("invalid port number: %d (must be between 1 and 65535)", port)
}
return nil
}