URLegit is a library for validating URLs.
URL validation is complex and very specific to the task at hand. This library's goal is to provide a toolkit for making pre-flight checks against a URL easier.
package main
import (
"fmt"
"github.com/xmidt-org/urlegit"
)
func main() {
c, err := urlegit.New(
urlegit.OnlyScheme("https"),
urlegit.ForbidSpecialUseDomains(),
)
if err != nil {
panic(err)
}
url := "https://github.com"
fmt.Printf("Is %q allowed? %t\n", url, c.Legit(url))
// Output:
// Is "https://github.com" allowed? true
}
- https://www.w3.org/Addressing/URL/5_BNF.html
- https://datatracker.ietf.org/doc/html/rfc1738
- https://www.iana.org/assignments/special-use-domain-names/special-use-domain-names.xhtml
- https://www.iana.org/assignments/iana-ipv4-special-registry/iana-ipv4-special-registry.xhtml
- https://www.iana.org/assignments/iana-ipv6-special-registry/iana-ipv6-special-registry.xhtml
This library originally started of in xmidt-org/ancla as webhook URL validation code. Here is a perma link to that code.