EscapedFragment returns the escaped form of u.Fragment. In general there are multiple possible escaped forms of any fragment. EscapedFragment returns u.RawFragment when it is a valid escaping of u.Fragment. Otherwise EscapedFragment ignores u.RawFragment and computes an escaped form on its own. The [URL.String] method uses EscapedFragment to construct its result. In general, code should call EscapedFragment instead of reading u.RawFragment directly.
EscapedPath returns the escaped form of u.Path. In general there are multiple possible escaped forms of any path. EscapedPath returns u.RawPath when it is a valid escaping of u.Path. Otherwise EscapedPath ignores u.RawPath and computes an escaped form on its own. The [URL.String] and [URL.RequestURI] methods use EscapedPath to construct their results. In general, code should call EscapedPath instead of reading u.RawPath directly.
JoinPath returns a new [URL] with the provided path elements joined to any existing path and the resulting path cleaned of any ./ or ../ elements. Any sequences of multiple / characters will be reduced to a single /. Path elements must already be in escaped form, as produced by [PathEscape].
Rest ...elem: string[]ResolveReference resolves a URI reference to an absolute URI from an absolute base URI u, per RFC 3986 Section 5.2. The URI reference may be relative or absolute. ResolveReference always returns a new [URL] instance, even if the returned URL is identical to either the base or reference. If ref is an absolute URL, then ResolveReference ignores base and returns a copy of ref.
String reassembles the [URL] into a valid URL string. The general form of the result is one of:
scheme:opaque?query#fragment
scheme://userinfo@host/path?query#fragment
If u.Opaque is non-empty, String uses the first form; otherwise it uses the second form. Any non-ASCII characters in host are escaped. To obtain the path, String uses u.EscapedPath().
In the second form, the following rules apply:
- if u.Scheme is empty, scheme: is omitted.
- if u.User is nil, userinfo@ is omitted.
- if u.Host is empty, host/ is omitted.
- if u.Scheme and u.Host are empty and u.User is nil,
the entire scheme://userinfo@host/ is omitted.
- if u.Host is non-empty and u.Path begins with a /,
the form host/path does not add its own /.
- if u.RawQuery is empty, ?query is omitted.
- if u.Fragment is empty, #fragment is omitted.
ForceQuery indicates whether the original URL contained a query ('?') character. When set, the String method will include a trailing '?', even when RawQuery is empty.
OmitHost indicates the URL has an empty host (authority). When set, the String method will not include the host when it is empty.
RawFragment is an optional field containing an encoded fragment hint. See the EscapedFragment method for more details.
In general, code should call EscapedFragment instead of reading RawFragment.
RawPath is an optional field containing an encoded path hint. See the EscapedPath method for more details.
In general, code should call EscapedPath instead of reading RawPath.
RawQuery contains the encoded query values, without the initial '?'. Use URL.Query to decode the query.
Optional userGenerated using TypeDoc
A URL represents a parsed URL (technically, a URI reference).
The general form represented is:
URLs that do not start with a slash after the scheme are interpreted as:
The Host field contains the host and port subcomponents of the URL. When the port is present, it is separated from the host with a colon. When the host is an IPv6 address, it must be enclosed in square brackets: "[fe80::1]:80". The [net.JoinHostPort] function combines a host and port into a string suitable for the Host field, adding square brackets to the host when necessary.
Note that the Path field is stored in decoded form: /%47%6f%2f becomes /Go/. A consequence is that it is impossible to tell which slashes in the Path were slashes in the raw URL and which were %2f. This distinction is rarely important, but when it is, the code should use the [URL.EscapedPath] method, which preserves the original encoding of Path. The Fragment field is also stored in decoded form, use [URL.EscapedFragment] to retrieve the original encoding.
The [URL.String] method uses the [URL.EscapedPath] method to obtain the path.