You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
gostring/url.go

46 lines
895 B

package gostring
import (
"strings"
)
// CompleteUrlHttp 补全 URL
func CompleteUrlHttp(url string) string {
if url == "" {
return url
}
if strings.HasPrefix(url, "http://") {
return url
}
if strings.HasPrefix(url, "//") {
url = "http:" + url
} else if strings.HasPrefix(url, "://") {
url = "http" + url
} else if strings.HasPrefix(url, "https://") {
url = Replace(url, "https://", "http://")
} else {
url = "http://" + url
}
return url
}
// CompleteUrlHttps 补全 URL
func CompleteUrlHttps(url string) string {
if url == "" {
return url
}
if strings.HasPrefix(url, "https://") {
return url
}
if strings.HasPrefix(url, "//") {
url = "https:" + url
} else if strings.HasPrefix(url, "://") {
url = "https" + url
} else if strings.HasPrefix(url, "http://") {
url = Replace(url, "http://", "https://")
} else {
url = "https://" + url
}
return url
}