func ValidateHostname(hostname string) (string, error) {
	if len(hostname) == 0 {
		return "", errors.New("must not be empty")
	}
	if len(hostname) < domainNameMinLength || len(hostname) > domainNameMaxLength {
		return "", fmt.Errorf("must be at least %d and at most %d characters", domainNameMinLength, domainNameMaxLength)
	}

	parsedHost := hostname
	if host, _, err := net.SplitHostPort(hostname); err == nil {
		parsedHost = host
	}
	if net.ParseIP(parsedHost) != nil {
		// hostname is a valid IP address
		return hostname, nil
	}
	if err := isValidDomainName(parsedHost); err != nil {
		return "", fmt.Errorf("must either be a valid IP address or domain name: invalid domain name %q, %w", hostname, err)
	}
	return hostname, nil
}
// ValidateHostname verifies the given hostname is a well-formed IP address
// or domain name, optionally including a port, and returns the hostname part.
ValidateHostname verifies the given hostname is a well-formed IP address
or domain name, optionally including a port, and returns the hostname part.
// ValidateHostname verifies the given hostname is a well - formed IP address // or domain name optionally including a port and returns the hostname part .
func ValidateHostname(hostname string) (string, error) {
	if len(hostname) == 0 {
		return "", errors.New("must not be empty")
	}
	if len(hostname) < domainNameMinLength || len(hostname) > domainNameMaxLength {
		return "", fmt.Errorf("must be at least %d and at most %d characters", domainNameMinLength, domainNameMaxLength)
	}
	parsedHost := hostname
	if host, _, err := net.SplitHostPort(hostname); err == nil {
		parsedHost = host
	}
	if net.ParseIP(parsedHost) != nil {
		return hostname, nil
	}
	if err := isValidDomainName(parsedHost); err != nil {
		return "", fmt.Errorf("must either be a valid IP address or domain name: invalid domain name %q, %w", hostname, err)
	}
	return hostname, nil
}
func ValidateHostname ( hostname string ) ( string , error ) { if len ( hostname ) == 0 { return " " , errors . New ( " " ) } if len ( hostname ) < domainNameMinLength || len ( hostname ) > domainNameMaxLength { return " " , fmt . Errorf ( " " , domainNameMinLength , domainNameMaxLength ) } parsedHost := hostname if host , _ , err := net . SplitHostPort ( hostname ) ; err == nil { parsedHost = host } if net . ParseIP ( parsedHost ) != nil { return hostname , nil } if err := isValidDomainName ( parsedHost ) ; err != nil { return " " , fmt . Errorf ( " " , hostname , err ) } return hostname , nil }
ValidateHostname verifies the given hostname is a well-formed IP address
or domain name, optionally including a port, and returns the hostname part.
ValidateHostname verifies the given hostname is a well - formed IP address or domain name optionally including a port and returns the hostname part .
// hostname is a valid IP address