Namespace: go.std.net.url
v1.0Contents
Summary
Provides a low-level interface to the net/url package.
Package url parses URLs and implements query escaping.
Index
- *Error
- *EscapeError
- *InvalidHostError
- *URL
- *Userinfo
- *Values
- Error
- EscapeError
- InvalidHostError
- JoinPath
- Parse
- ParseQuery
- ParseRequestURI
- PathEscape
- PathUnescape
- QueryEscape
- QueryUnescape
- URL
- User
- UserPassword
- Userinfo
- Values
- arrayOfError
- arrayOfEscapeError
- arrayOfInvalidHostError
- arrayOfURL
- arrayOfUserinfo
- arrayOfValues
Legend
-
Constant
Variable
Function
Macro
Special form
Type
GoVar
Receiver/Method
Constants
Constants are variables with :const true in their metadata. Joker currently does not recognize them as special; as such, it allows redefining them or their values.-
(None.)
Variables
-
(None.)
Functions, Macros, and Special Forms
-
JoinPath
Function v1.0(JoinPath base & elem)
JoinPath returns a URL string with the provided path elements joined to
the existing path of base and the resulting path cleaned of any ./ or ../ elements.
Go input arguments: (base string, elem ...string)
Go returns: (result string, err error)
Joker input arguments: [^String base, & ^String elem]
Joker returns: [^String result, ^Error err] -
Parse
Function v1.0(Parse rawURL)
Parse parses a raw url into a URL structure.
The url may be relative (a path, without a host) or absolute
(starting with a scheme). Trying to parse a hostname and path
without a scheme is invalid but may not necessarily return an
error, due to parsing ambiguities.
Go input arguments: (rawURL string)
Go returns: (*URL, error)
Joker input arguments: [^String rawURL]
Joker returns: [^*URL, ^Error] -
ParseQuery
Function v1.0(ParseQuery query)
ParseQuery parses the URL-encoded query string and returns
a map listing the values specified for each key.
ParseQuery always returns a non-nil map containing all the
valid query parameters found; err describes the first decoding error
encountered, if any.
Query is expected to be a list of key=value settings separated by ampersands.
A setting without an equals sign is interpreted as a key set to an empty
value.
Settings containing a non-URL-encoded semicolon are considered invalid.
Go input arguments: (query string)
Go returns: (Values, error)
Joker input arguments: [^String query]
Joker returns: [^Values, ^Error] -
ParseRequestURI
Function v1.0(ParseRequestURI rawURL)
ParseRequestURI parses a raw url into a URL structure. It assumes that
url was received in an HTTP request, so the url is interpreted
only as an absolute URI or an absolute path.
The string url is assumed not to have a #fragment suffix.
(Web browsers strip #fragment before sending the URL to a web server.)
Go input arguments: (rawURL string)
Go returns: (*URL, error)
Joker input arguments: [^String rawURL]
Joker returns: [^*URL, ^Error] -
PathEscape
Function v1.0(PathEscape s)
PathEscape escapes the string so it can be safely placed inside a URL path segment,
replacing special characters (including /) with %XX sequences as needed.
Go input arguments: (s string)
Go returns: string
Joker input arguments: [^String s]
Joker returns: ^String -
PathUnescape
Function v1.0(PathUnescape s)
PathUnescape does the inverse transformation of PathEscape,
converting each 3-byte encoded substring of the form "%AB" into the
hex-decoded byte 0xAB. It returns an error if any % is not followed
by two hexadecimal digits.
PathUnescape is identical to QueryUnescape except that it does not
unescape '+' to ' ' (space).
Go input arguments: (s string)
Go returns: (string, error)
Joker input arguments: [^String s]
Joker returns: [^String, ^Error] -
QueryEscape
Function v1.0(QueryEscape s)
QueryEscape escapes the string so it can be safely placed
inside a URL query.
Go input arguments: (s string)
Go returns: string
Joker input arguments: [^String s]
Joker returns: ^String -
QueryUnescape
Function v1.0(QueryUnescape s)
QueryUnescape does the inverse transformation of QueryEscape,
converting each 3-byte encoded substring of the form "%AB" into the
hex-decoded byte 0xAB.
It returns an error if any % is not followed by two hexadecimal
digits.
Go input arguments: (s string)
Go returns: (string, error)
Joker input arguments: [^String s]
Joker returns: [^String, ^Error] -
User
Function v1.0(User username)
User returns a Userinfo containing the provided username
and no password set.
Go input arguments: (username string)
Go returns: *Userinfo
Joker input arguments: [^String username]
Joker returns: ^*Userinfo -
UserPassword
Function v1.0(UserPassword username password)
UserPassword returns a Userinfo containing the provided username
and password.
This functionality should only be used with legacy web sites.
RFC 2396 warns that interpreting Userinfo this way
“is NOT RECOMMENDED, because the passing of authentication
information in clear text (such as URI) has proven to be a
security risk in almost every case where it has been used.”
Go input arguments: (username string, password string)
Go returns: *Userinfo
Joker input arguments: [^String username, ^String password]
Joker returns: ^*Userinfo
Types
-
*Error
Concrete Type v1.0Error reports an error and the operation and URL that caused it.
-
Error
Receiver for *Error v1.0([])
-
Temporary
Receiver for *Error v1.0([])
-
Timeout
Receiver for *Error v1.0([])
-
Unwrap
Receiver for *Error v1.0([])
-
*EscapeError
Concrete Type v1.0 -
*InvalidHostError
Concrete Type v1.0 -
*URL
Concrete Type v1.0A URL represents a parsed URL (technically, a URI reference).
The general form represented is:
[scheme:][//[userinfo@]host][/]path[?query][#fragment]
URLs that do not start with a slash after the scheme are interpreted as:
scheme:opaque[?query][#fragment]
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 RawPath, an optional field which only gets
set if the default encoding is different from Path.
URL's String method uses the EscapedPath method to obtain the path. See the
EscapedPath method for more details.
-
EscapedFragment
Receiver for *URL v1.0([])
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 String method uses EscapedFragment to construct its result.
In general, code should call EscapedFragment instead of
reading u.RawFragment directly.
-
EscapedPath
Receiver for *URL v1.0([])
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 String and RequestURI methods use EscapedPath to construct
their results.
In general, code should call EscapedPath instead of
reading u.RawPath directly.
-
Hostname
Receiver for *URL v1.0([])
Hostname returns u.Host, stripping any valid port number if present.
If the result is enclosed in square brackets, as literal IPv6 addresses are,
the square brackets are removed from the result.
-
IsAbs
Receiver for *URL v1.0([])
IsAbs reports whether the URL is absolute.
Absolute means that it has a non-empty scheme.
-
JoinPath
Receiver for *URL v1.0([elem])
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 /.
-
MarshalBinary
Receiver for *URL v1.0([])
-
Parse
Receiver for *URL v1.0([ref])
Parse parses a URL in the context of the receiver. The provided URL
may be relative or absolute. Parse returns nil, err on parse
failure, otherwise its return value is the same as ResolveReference.
-
Port
Receiver for *URL v1.0([])
Port returns the port part of u.Host, without the leading colon.
If u.Host doesn't contain a valid numeric port, Port returns an empty string.
-
Query
Receiver for *URL v1.0([])
Query parses RawQuery and returns the corresponding values.
It silently discards malformed value pairs.
To check errors use ParseQuery.
-
Redacted
Receiver for *URL v1.0([])
Redacted is like String but replaces any password with "xxxxx".
Only the password in u.URL is redacted.
-
RequestURI
Receiver for *URL v1.0([])
RequestURI returns the encoded path?query or opaque?query
string that would be used in an HTTP request for u.
-
ResolveReference
Receiver for *URL v1.0([ref])
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
Receiver for *URL v1.0([])
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.
-
UnmarshalBinary
Receiver for *URL v1.0([text])
-
*Userinfo
Concrete Type v1.0The Userinfo type is an immutable encapsulation of username and
password details for a URL. An existing Userinfo value is guaranteed
to have a username set (potentially empty, as allowed by RFC 2396),
and optionally a password.
-
Password
Receiver for *Userinfo v1.0([])
Password returns the password in case it is set, and whether it is set.
-
String
Receiver for *Userinfo v1.0([])
String returns the encoded userinfo information in the standard form
of "username[:password]".
-
Username
Receiver for *Userinfo v1.0([])
Username returns the username.
-
*Values
Concrete Type v1.0Values maps a string key to a list of values.
It is typically used for query parameters and form values.
Unlike in the http.Header map, the keys in a Values map
are case-sensitive.
-
Error
Concrete Type v1.0Error reports an error and the operation and URL that caused it.
-
EscapeError
Concrete Type v1.0 -
Error
Receiver for EscapeError v1.0([])
-
InvalidHostError
Concrete Type v1.0 -
Error
Receiver for InvalidHostError v1.0([])
-
URL
Concrete Type v1.0A URL represents a parsed URL (technically, a URI reference).
The general form represented is:
[scheme:][//[userinfo@]host][/]path[?query][#fragment]
URLs that do not start with a slash after the scheme are interpreted as:
scheme:opaque[?query][#fragment]
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 RawPath, an optional field which only gets
set if the default encoding is different from Path.
URL's String method uses the EscapedPath method to obtain the path. See the
EscapedPath method for more details.
-
Userinfo
Concrete Type v1.0The Userinfo type is an immutable encapsulation of username and
password details for a URL. An existing Userinfo value is guaranteed
to have a username set (potentially empty, as allowed by RFC 2396),
and optionally a password.
-
Values
Concrete Type v1.0Values maps a string key to a list of values.
It is typically used for query parameters and form values.
Unlike in the http.Header map, the keys in a Values map
are case-sensitive.
-
Add
Receiver for Values v1.0([key value])
Add adds the value to key. It appends to any existing
values associated with key.
-
Del
Receiver for Values v1.0([key])
Del deletes the values associated with key.
-
Encode
Receiver for Values v1.0([])
Encode encodes the values into “URL encoded” form
("bar=baz&foo=quux") sorted by key.
-
Get
Receiver for Values v1.0([key])
Get gets the first value associated with the given key.
If there are no values associated with the key, Get returns
the empty string. To access multiple values, use the map
directly.
-
Has
Receiver for Values v1.0([key])
Has checks whether a given key is set.
-
Set
Receiver for Values v1.0([key value])
Set sets the key to value. It replaces any existing
values.
-
arrayOfError
Concrete Type v1.0Error reports an error and the operation and URL that caused it.
-
arrayOfEscapeError
Concrete Type v1.0 -
arrayOfInvalidHostError
Concrete Type v1.0 -
arrayOfURL
Concrete Type v1.0A URL represents a parsed URL (technically, a URI reference).
The general form represented is:
[scheme:][//[userinfo@]host][/]path[?query][#fragment]
URLs that do not start with a slash after the scheme are interpreted as:
scheme:opaque[?query][#fragment]
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 RawPath, an optional field which only gets
set if the default encoding is different from Path.
URL's String method uses the EscapedPath method to obtain the path. See the
EscapedPath method for more details.
-
arrayOfUserinfo
Concrete Type v1.0The Userinfo type is an immutable encapsulation of username and
password details for a URL. An existing Userinfo value is guaranteed
to have a username set (potentially empty, as allowed by RFC 2396),
and optionally a password.
-
arrayOfValues
Concrete Type v1.0Values maps a string key to a list of values.
It is typically used for query parameters and form values.
Unlike in the http.Header map, the keys in a Values map
are case-sensitive.