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 ¶
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 ¶
SyntaxError reports the component of a reference that breaks the grammar, and why.
func (*SyntaxError) Error ¶
func (e *SyntaxError) Error() string