uriref

package
v1.70.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 2, 2026 License: MIT Imports: 3 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package uriref reads a URI reference as RFC 3986 defines it, which is the format `uri-reference` the OpenAPI Specification's schemas require of its URL fields.

It implements the grammar directly rather than leaning on net/url, which is a parser for the URLs a client will fetch and not a validator of the grammar: it takes a second "@" in userinfo, refuses a percent-encoded character in a host, and reads every bracketed host as IPv6, so it refuses IPvFuture. A caller that needs a rule beyond the grammar (an http URL must have a host, RFC 9110) asks the Reference this package returns.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Reference

type Reference struct {
	// Scheme is empty for a relative reference.
	Scheme string
	// HasAuthority reports whether the reference began its hierarchical part with
	// "//". An authority may be empty, so this is not the same as Host != "".
	HasAuthority bool
	// Userinfo, Host and Port are the parts of the authority. An IP-literal Host
	// keeps its brackets. Port is the digits after the colon, and is empty when
	// the colon is absent or has nothing after it.
	Userinfo string
	Host     string
	Port     string
	// Path may be empty. Query and Fragment are without their "?" and "#"; the
	// grammar cannot tell an absent query from an empty one, and neither can
	// this type.
	Path     string
	Query    string
	Fragment string
}

Reference is a URI reference split into the components of RFC 3986 section 3. Every component is kept as written, percent-encoding included.

func Parse

func Parse(s string) (Reference, error)

Parse reads s as a URI reference:

URI-reference = URI / relative-ref
URI           = scheme ":" hier-part [ "?" query ] [ "#" fragment ]
relative-ref  = relative-part [ "?" query ] [ "#" fragment ]

The empty string is the grammar's empty relative reference, and Parse accepts it; a field that must hold something rejects it for itself.

The error is a *SyntaxError naming the first component that fails.

type SyntaxError

type SyntaxError struct {
	Component string
	Reason    string
}

SyntaxError reports the component of a reference that breaks the grammar, and why.

func (*SyntaxError) Error

func (e *SyntaxError) Error() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL