Skip to content

jbrekelmans/go-url

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Go Reference

URL validation

Comprehensive URL validation suitable for sanitizing/normalizing untrusted inputs.

Usage

go get github.com/jbrekelmans/go-url@latest

import jurl "github.com/jbrekelmans/go-url"

u, err := jurl.ValidateURL("https://bla@github.com:443//?foo=bar#xyz", jurl.ValidateURLOptions{
    Abs:                      jurl.NewBool(true),  // Require the URL to be absolute
    AllowedSchemes:           []string{"https"},   // Only allow scheme https
    NormalizePort:            jurl.NewBool(false), // Remove port if it is the default port for the URL.
    StripFragment:            true,
    StripQuery:               true,                // Remove query string.
    StripPathTrailingSlashes: true,
    StripUser:                true,
})
if err != nil {
    log.Fatal(err)
}
log.Printf("%v", u) // Outputs https://github.com

About

Comprehensive URL validation suitable for sanitizing/normalizing untrusted inputs

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages