Initial code commit
This commit is contained in:
34
pkg/utils/validation.go
Normal file
34
pkg/utils/validation.go
Normal file
@@ -0,0 +1,34 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user