A 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.
// append a query ('?') even if RawQuery is empty
// fragment for references, without '#'
// host or host:port
// encoded opaque data
// path (relative paths may omit leading slash)
// encoded fragment hint (see EscapedFragment method)
// encoded path hint (see EscapedPath method)
// encoded query values, without '?'
Schemestring
// username and password information
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 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 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 reports whether the URL is absolute.
Absolute means that it has a non-empty scheme.
(*T) MarshalBinary() (text []byte, err error)
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 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 parses RawQuery and returns the corresponding values.
It silently discards malformed value pairs.
To check errors use ParseQuery.
Redacted is like String but replaces any password with "xxxxx".
Only the password in u.URL is redacted.
RequestURI returns the encoded path?query or opaque?query
string that would be used in an HTTP request for u.
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.
(*T) UnmarshalBinary(text []byte) error
setFragment is like setPath but for Fragment/RawFragment.
setPath sets the Path and RawPath fields of the URL based on the provided
escaped path p. It maintains the invariant that RawPath is only specified
when it differs from the default encoding of the path.
For example:
- setPath("/foo/bar") will set Path="/foo/bar" and RawPath=""
- setPath("/foo%2fbar") will set Path="/foo/bar" and RawPath="/foo%2fbar"
setPath will return an error only if the provided path contains an invalid
escaping.
*T : encoding.BinaryMarshaler
*T : encoding.BinaryUnmarshaler
*T : fmt.Stringer
*T : github.com/neo4j/neo4j-go-driver/v4/neo4j.ServerAddress
*T : context.stringer
*T : crypto/hmac.marshalable
*T : runtime.stringer
func Parse(rawurl string) (*URL, error)
func ParseRequestURI(rawurl string) (*URL, error)
func (*URL).Parse(ref string) (*URL, error)
func (*URL).ResolveReference(ref *URL) *URL
func github.com/neo4j/neo4j-go-driver/v4/neo4j.Driver.Target() URL
func parse(rawurl string, viaRequest bool) (*URL, error)
func crypto/x509.parseSANExtension(value []byte) (dnsNames, emailAddresses []string, ipAddresses []net.IP, uris []*URL, err error)
func github.com/neo4j/neo4j-go-driver/v4/neo4j.newServerAddressURL(hostname string, port string) *URL
func (*URL).ResolveReference(ref *URL) *URL
func crypto/x509.marshalSANs(dnsNames, emailAddresses []string, ipAddresses []net.IP, uris []*URL) (derBytes []byte, err error)
func crypto/x509.matchURIConstraint(uri *URL, constraint string) (bool, error)
func github.com/neo4j/neo4j-go-driver/v4/neo4j.routingContextFromUrl(useRouting bool, u *URL) (map[string]string, error)
The 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.
passwordstringpasswordSetboolusernamestring
Password returns the password in case it is set, and whether it is set.
String returns the encoded userinfo information in the standard form
of "username[:password]".
Username returns the username.
*T : fmt.Stringer
*T : context.stringer
*T : runtime.stringer
func User(username string) *Userinfo
func UserPassword(username, password string) *Userinfo
func parseAuthority(authority string) (user *Userinfo, host string, err error)
Values 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 adds the value to key. It appends to any existing
values associated with key.
Del deletes the values associated with key.
Encode encodes the values into ``URL encoded'' form
("bar=baz&foo=quux") sorted by 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.
Set sets the key to value. It replaces any existing
values.
func ParseQuery(query string) (Values, error)
func (*URL).Query() Values
func parseQuery(m Values, query string) (err error)
Package-Level Functions (total 26, in which 9 are exported)
Parse parses rawurl into a URL structure.
The rawurl 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.
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 or semicolons. A setting without an equals sign is
interpreted as a key set to an empty value.
ParseRequestURI parses rawurl into a URL structure. It assumes that
rawurl was received in an HTTP request, so the rawurl is interpreted
only as an absolute URI or an absolute path.
The string rawurl is assumed not to have a #fragment suffix.
(Web browsers strip #fragment before sending the URL to a web server.)
PathEscape escapes the string so it can be safely placed inside a URL path segment,
replacing special characters (including /) with %XX sequences as needed.
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).
QueryEscape escapes the string so it can be safely placed
inside a URL query.
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.
User returns a Userinfo containing the provided username
and no password set.
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.''
parse parses a URL from a string in one of two contexts. If
viaRequest is true, the URL is assumed to have arrived via an HTTP request,
in which case only absolute URLs or path-absolute relative URLs are allowed.
If viaRequest is false, all forms of relative URLs are allowed.
resolvePath applies special path segments from refs and applies
them to base, per RFC 3986.
Return true if the specified character should be escaped when
appearing in a URL string, according to RFC 3986.
Please be informed that for now shouldEscape does not check all
reserved characters correctly. See golang.org/issue/5684.
split slices s into two substrings separated by the first occurrence of
sep. If cutc is true then sep is excluded from the second substring.
If sep does not occur in s then s and the empty string is returned.
splitHostPort separates host and port. If the port is not valid, it returns
the entire input as host, and it doesn't check the validity of the host.
Unlike net.SplitHostPort, but per RFC 3986, it requires ports to be numeric.
stringContainsCTLByte reports whether s contains any ASCII control character.
unescape unescapes a string; the mode specifies
which section of the URL string is being unescaped.
validEncoded reports whether s is a valid encoded path or fragment,
according to mode.
It must not contain any bytes that require escaping during encoding.
validOptionalPort reports whether port is either an empty string
or matches /^:\d*$/
validUserinfo reports whether s is a valid userinfo string per RFC 3986
Section 3.2.1:
userinfo = *( unreserved / pct-encoded / sub-delims / ":" )
unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
sub-delims = "!" / "$" / "&" / "'" / "(" / ")"
/ "*" / "+" / "," / ";" / "="
It doesn't validate pct-encoded. The caller does that via func unescape.
Package-Level Constants (total 8, none are exported)
The pages are generated with Goldsv0.4.2. (GOOS=darwin GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds.