A Golang package for URL parsing and normalization.
github.com/hueristiq/url | net/url |
---|---|
url.Parse("example.com") |
url.Parse("example.com") |
url.Parse("localhost:8080") |
url.Parse("localhost:8080") |
url.Parse("user.local:8000/path") |
url.Parse("user.local:8000/path") |
import "github.com/hueristiq/url"
func main() {
url, _ := url.Parse("example.com")
// url.Scheme == "http"
// url.Host == "example.com"
fmt.Print(url)
// Prints http://example.com
}
The url.Normalize() function normalizes the URL using the predefined subset of Purell flags.
import "github.com/hueristiq/url"
func main() {
url, _ := url.Parse("localhost:80///x///y/z/../././index.html?b=y&a=x#t=20")
normalized, _ := url.Normalize(url)
fmt.Print(normalized)
// Prints http://localhost/x/y/index.html?a=x&b=y#t=20
}