andydotxyz / uri

RFC 3986 compliant uri builder/parser

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

uri

Build Status codecov license Go Reference GolangCI Go Report Card

Package uri is meant to be an RFC 3986 compliant URI builder, parser and validator for Go.

It supports strict RFC validation for URI and URI relative references.

Usage

Parsing
	u, err := Parse("https://example.com:8080/path")
	if err != nil {
		fmt.Printf("Invalid URI")
	} else {
		fmt.Printf("%s", u.Scheme())
	}
	// Output: https
	u, err := ParseReference("//example.com/path")
	if err != nil {
		fmt.Printf("Invalid URI reference")
	} else {
		fmt.Printf("%s", u.Authority().Path())
	}
	// Output: /path
Validation
    isValid := IsURI("urn://example.com?query=x#fragment/path") // true
    isValid= IsURI("//example.com?query=x#fragment/path") // false

    isValid= IsURIReference("//example.com?query=x#fragment/path") // true
Building

Reference specifications

Internationalization support:

IPv6 addressing scheme reference and erratum:

This allows for stricter conformance than the net/url in the Go standard libary, which provides a workable but loose implementation of the RFC.

This package concentrates on RFC 3986 strictness for URI validation. At the moment, there is no attempt to normalize or auto-escape strings. For url normalization, see PuerkitoBio/purell.

Disclaimer

Not supported:

  • provisions for "IPvFuture" are not implemented.

Hostnames vs domain names:

  • a list of common schemes triggers the validation of hostname against domain name rules.

Example:

Credits

Tests have been aggregated from test suites of URI validators from other languages: Perl, Python, Scala, .Net. and the Go url standard library.

This package was initially based on the work from ttacon/uri (credits: Trey Tacon). Extra features like MySQL URIs present in the original repo have been removed.

About

RFC 3986 compliant uri builder/parser

License:MIT License


Languages

Language:Go 98.2%Language:Python 1.2%Language:Perl 0.6%