adam-gui/vendor/github.com/fredbi/uri/README.md
2024-04-29 19:13:50 +02:00

2.9 KiB

uri

Lint CI Coverage Status GitHub tag (latest by date) Go Reference license Go Report Card

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

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

(to be continued...)

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:

  • ftp://host, http://host default to validating a proper hostname.

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.

A lot of improvements have been brought by the incredible guys at fyne-io. Thanks all.