func IsAmazonEndpoint(endpointURL url.URL) bool {
	if endpointURL.Host == "s3-external-1.amazonaws.com" || endpointURL.Host == "s3.amazonaws.com" {
		return true
	}
	return GetRegionFromURL(endpointURL) != ""
}
IsAmazonEndpoint - Match if it is exactly Amazon S3 endpoint.
package s3utils
import (
	"bytes"
	"encoding/hex"
	"errors"
	"net"
	"net/url"
	"regexp"
	"sort"
	"strings"
	"unicode/utf8"
)
var sentinelURL = url.URL{}
func IsValidDomain(host string) bool {
	host = strings.TrimSpace(host)
	if len(host) == 0 || len(host) > 255 {
		return false
	}
	if host[len(host)-1:] == "-" || host[:1] == "-" {
		return false
	}
	if host[len(host)-1:] == "_" || host[:1] == "_" {
		return false
	}
	if host[:1] == "." {
		return false
	}
	if strings.ContainsAny(host, "`~!@#$%^&*()+={}[]|\\\"';:><?/") {
		return false
	}
	return true
}
func IsValidIP(ip string) bool {
	return net.ParseIP(ip) != nil
}
func IsVirtualHostSupported(endpointURL url.URL, bucketName string) bool {
	if endpointURL == sentinelURL {
		return false
	}
	if endpointURL.Scheme == "https" && strings.Contains(bucketName, ".") {
		return false
	}
	return IsAmazonEndpoint(endpointURL) || IsGoogleEndpoint(endpointURL) || IsAliyunOSSEndpoint(endpointURL)
}
var amazonS3HostHyphen = regexp.MustCompile(`^s3-(.*?).amazonaws.com$`)
var amazonS3HostDualStack = regexp.MustCompile(`^s3.dualstack.(.*?).amazonaws.com$`)
var amazonS3HostDot = regexp.MustCompile(`^s3.(.*?).amazonaws.com$`)
var amazonS3ChinaHost = regexp.MustCompile(`^s3.(cn.*?).amazonaws.com.cn$`)
var elbAmazonRegex = regexp.MustCompile(`elb(.*?).amazonaws.com$`)
var elbAmazonCnRegex = regexp.MustCompile(`elb(.*?).amazonaws.com.cn$`)
func GetRegionFromURL(endpointURL url.URL) string {
	if endpointURL == sentinelURL {
		return ""
	}
	if endpointURL.Host == "s3-external-1.amazonaws.com" {
		return ""
	}
	if IsAmazonGovCloudEndpoint(endpointURL) {
		return "us-gov-west-1"
	}
	if elbAmazonRegex.MatchString(endpointURL.Host) || elbAmazonCnRegex.MatchString(endpointURL.Host) {
		return ""
	}
	parts := amazonS3HostDualStack.FindStringSubmatch(endpointURL.Host)
	if len(parts) > 1 {
		return parts[1]
	}
	parts = amazonS3HostHyphen.FindStringSubmatch(endpointURL.Host)
	if len(parts) > 1 {
		return parts[1]
	}
	parts = amazonS3ChinaHost.FindStringSubmatch(endpointURL.Host)
	if len(parts) > 1 {
		return parts[1]
	}
	parts = amazonS3HostDot.FindStringSubmatch(endpointURL.Host)
	if len(parts) > 1 {
		return parts[1]
	}
	return ""
}
func IsAliyunOSSEndpoint(endpointURL url.URL) bool {
	return strings.HasSuffix(endpointURL.Host, "aliyuncs.com")
}