urlidentification is a library to help you identify what kind of URL your have.
It is based on RFC 3986's definitions for:
- An absolute URL
- A relative reference to an absolute path
- A relative path reference
- A network-path reference
package main
import "fmt"
import "net/url"
import "github.com/statusmachine/urlidentification"
func main() {
absoluteUrl, _ := url.Parse("https://www.statusmachine.com/subdir/page.html")
networkPathReference, _ := url.Parse("//www.statusmachine.com/subdir/page.html")
relativeRefWithAbsPath, _ := url.Parse("/subdir/page.html")
relativePathRef, _ := url.Parse("subdir/page.html")
fmt.Println("is absolute url:", urlidentification.IsAbsoluteURL(absoluteUrl))
fmt.Println("is network path reference:", urlidentification.IsNetworkPathReferenceURL(networkPathReference))
fmt.Println("is relative reference with absolute path:", urlidentification.IsRelativeReferenceWithAbsolutePathURL(relativeRefWithAbsPath))
fmt.Println("is relative path reference:", urlidentification.IsRelativePathReferenceURL(relativePathRef))
identifiedURL, _ := urlidentification.IdentifyURLString("http://google.com")
fmt.Println(identifiedURL == urlidentification.Absolute)
}
Running the previous program should outpout:
is absolute url: true
is network path reference: true
is relative reference with absolute path: true
is relative path reference: true
true
The BSD 3-Clause license.