net/url
import "net/url"
Go 1.26.1
Functions
func JoinPath(base string, elem ...string) (string, error)
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. Path elements must already be in escaped form, as produced by [PathEscape].
net/url/url.go:1316
func Parse(rawURL string) (*URL, error)
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.
net/url/url.go:399
func ParseQuery(query string) (Values, error)
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.
net/url/url.go:928
func ParseRequestURI(rawURL string) (*URL, error)
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.)
net/url/url.go:420
func PathEscape(s string) string
PathEscape escapes the string so it can be safely placed inside a [URL] path segment, replacing special characters (including /) with %XX sequences as needed.
net/url/url.go:192
func PathUnescape(s string) (string, error)
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).
net/url/url.go:100
func QueryEscape(s string) string
QueryEscape escapes the string so it can be safely placed inside a [URL] query.
net/url/url.go:186
func QueryUnescape(s string) (string, error)
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.
net/url/url.go:89
func User(username string) *Userinfo
User returns a [Userinfo] containing the provided username and no password set.
net/url/url.go:311
func UserPassword(username string, password string) *Userinfo
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.”
net/url/url.go:323
Types
type Error struct {
Op string
URL string
Err error
}Error reports an error and the operation and URL that caused it.
net/url/url.go:33
func (e *Error) Error() string
net/url/url.go:40
func (e *Error) Temporary() bool
net/url/url.go:49
func (e *Error) Timeout() bool
net/url/url.go:42
func (e *Error) Unwrap() error
net/url/url.go:39
type EscapeError string
net/url/url.go:67
func (e EscapeError) Error() string
net/url/url.go:69
type InvalidHostError string
net/url/url.go:73
func (e InvalidHostError) Error() string
net/url/url.go:75
type URL struct {
Scheme string
Opaque string // encoded opaque data
User *Userinfo // username and password information
Host string // "host" or "host:port" (see Hostname and...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] 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 [n...
net/url/url.go:276
func (u *URL) AppendBinary(b []byte) ([]byte, error)
net/url/url.go:1217
func (u *URL) EscapedFragment() string
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.
net/url/url.go:746
func (u *URL) EscapedPath() string
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.
net/url/url.go:683
func (u *URL) Hostname() string
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.
net/url/url.go:1179
func (u *URL) IsAbs() bool
IsAbs reports whether the [URL] is absolute. Absolute means that it has a non-empty scheme.
net/url/url.go:1087
func (u *URL) JoinPath(elem ...string) *URL
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].
net/url/url.go:1234
func (u *URL) MarshalBinary() ([]byte, error)
net/url/url.go:1213
func (u *URL) Parse(ref string) (*URL, 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 [URL.ResolveReference].
net/url/url.go:1094
func (u *URL) Port() string
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.
net/url/url.go:1187
func (u *URL) Query() Values
Query parses RawQuery and returns the corresponding values. It silently discards malformed value pairs. To check errors use [ParseQuery].
net/url/url.go:1150
func (u *URL) Redacted() string
Redacted is like [URL.String] but replaces any password with "xxxxx". Only the password in u.User is redacted.
net/url/url.go:865
func (u *URL) RequestURI() string
RequestURI returns the encoded path?query or opaque?query string that would be used in an HTTP request for u.
net/url/url.go:1157
func (u *URL) ResolveReference(ref *URL) *URL
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.
net/url/url.go:1108
func (u *URL) String() string
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. -...
net/url/url.go:794
func (u *URL) UnmarshalBinary(text []byte) error
net/url/url.go:1221
type Userinfo struct {
// contains filtered or unexported fields
}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.
net/url/url.go:331
func (u *Userinfo) Password() (string, bool)
Password returns the password in case it is set, and whether it is set.
net/url/url.go:346
func (u *Userinfo) String() string
String returns the encoded userinfo information in the standard form of "username[:password]".
net/url/url.go:355
func (u *Userinfo) Username() string
Username returns the username.
net/url/url.go:338
type Values map[string][]string
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.
net/url/url.go:881
func (v Values) Add(key string, value string)
Add adds the value to key. It appends to any existing values associated with key.
net/url/url.go:903
func (v Values) Del(key string)
Del deletes the values associated with key.
net/url/url.go:908
func (v Values) Encode() string
Encode encodes the values into “URL encoded” form ("bar=baz&foo=quux") sorted by key.
net/url/url.go:990
func (v Values) Get(key string) string
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.
net/url/url.go:887
func (v Values) Has(key string) bool
Has checks whether a given key is set.
net/url/url.go:913
func (v Values) Set(key string, value string)
Set sets the key to value. It replaces any existing values.
net/url/url.go:897