Skip to content

Instantly share code, notes, and snippets.

@gnuns
Last active October 1, 2019 11:08
Show Gist options
  • Save gnuns/c624adb7701d000f79b43b75b8935af3 to your computer and use it in GitHub Desktop.
Save gnuns/c624adb7701d000f79b43b75b8935af3 to your computer and use it in GitHub Desktop.
Golang: IsValidURL
import (
"net/url"
"golang.org/x/net/publicsuffix"
)
func IsValidURL(s string) bool {
u, err := url.Parse(s)
if err != nil {
return false
}
_, icann := publicsuffix.PublicSuffix(u.Hostname())
return icann
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment