https://github.com/xmidt-org/urlegit
Library to check if a URL is the kind you want.
https://github.com/xmidt-org/urlegit
Last synced: about 2 months ago
JSON representation
Library to check if a URL is the kind you want.
- Host: GitHub
- URL: https://github.com/xmidt-org/urlegit
- Owner: xmidt-org
- License: apache-2.0
- Created: 2023-08-13T05:03:14.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-12-04T12:33:42.000Z (6 months ago)
- Last Synced: 2025-03-23T12:32:53.431Z (2 months ago)
- Language: Go
- Size: 87.9 KB
- Stars: 0
- Watchers: 4
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# urlegit
URLegit is a library for validating URLs.
[](https://github.com/xmidt-org/urlegit/actions/workflows/ci.yml)
[](http://codecov.io/github/xmidt-org/urlegit?branch=main)
[](https://goreportcard.com/report/github.com/xmidt-org/urlegit)
[](https://github.com/xmidt-org/urlegit/blob/main/LICENSE)
[](https://github.com/xmidt-org/urlegit/releases)
[](https://pkg.go.dev/github.com/xmidt-org/urlegit)## Summary
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.## Usage
```go
package mainimport (
"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
}
```
[Go Playground](https://go.dev/play/p/QE93GEm6vrU)## Resources
- 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## Footnotes
This library originally started of in [xmidt-org/ancla](https://github.com/xmidt-org/ancla)
as webhook URL validation code. [Here](https://github.com/xmidt-org/ancla/blob/09a683a1ca368cfc020eaef9345f3ebd7b79e825/webhookValidationConfig.go#L27) is a perma
link to that code.