Documentation
¶
Index ¶
- Variables
- func BaseHost(baseURL string) (string, error)
- func BaseHostMatches(baseURL, domain string) (bool, error)
- func BaseOrigin(baseURL string) (scheme, host string, port int, err error)
- func BasePath(baseURL string) (string, error)
- func EncodeQuery(pairs [][2]string) string
- func Escape(s, keep string) string
- func FilePath(fileURL string) (string, error)
- func FileURL(path string) string
- func FormatHost(host string) string
- func LookupFilePath(ctx context.Context, fileURL string) (string, error)
- func Port(u *url.URL) (int, bool, error)
- func QueryPairs(query string) [][2]string
- func Unescape(s string) string
- type FileURLError
- type Parts
Constants ¶
This section is empty.
Variables ¶
var ErrInvalidHost = errors.New("invalid host")
Error for an authority whose host cannot be read: unbalanced brackets, brackets around anything but an IPv6 or IPvFuture literal, or text NFKC turns into delimiters
var ErrPortRange = errors.New("port out of range 0-65535")
Error for a port number above 65535
Functions ¶
func BaseHost ¶
Lowercased host of a base URL that may lack a scheme, trailing dots removed, empty when blank or hostless, an ErrInvalidHost error for an authority Split refuses
func BaseHostMatches ¶
Whether the host of a base URL is the domain or one of its subdomains, compared without case or trailing dots
func BaseOrigin ¶
Lowercased scheme, host and effective port of a base URL, 443 or 80 standing in for an absent http(s) port, all empty with port 0 when hostless or the port is not a number up to 65535
func BasePath ¶
Lowercased path of a base URL without trailing slashes, empty for a bare host, an ErrInvalidHost error for an authority Split refuses
func EncodeQuery ¶
Query string of name value pairs in the order given, names and values escaped as url.QueryEscape does
func Escape ¶
s percent-encoded byte by byte with upper case hex, ASCII letters, digits, -._~ and the ASCII bytes of keep left as they are
func FilePath ¶
Local path a file URL names, percent escapes decoded; an empty, localhost or own host name authority is local, another one is a UNC share on Windows and a *FileURLError elsewhere, as is a scheme other than file
func FileURL ¶
file URL of a local path made absolute first, file:///C:/... for a Windows drive path and file://server/share/... for a UNC path
func FormatHost ¶
Host as it goes in a URL authority: surrounding space trimmed, an IPv6 literal bracketed with its zone percent escaped as %25
func LookupFilePath ¶
Local path a file URL names like FilePath, an authority that resolves to a loopback address or one of this machine's interface addresses also counting as local
func Port ¶
Port number of a parsed URL, false when it names none, an error wrapping ErrPortRange for a number past 65535
func QueryPairs ¶
Name value pairs of a query string in their order, a plus sign read as a space, a malformed escape kept as text and a name without = given an empty value
Types ¶
type FileURLError ¶
type FileURLError struct {
URL, Reason string
}
Error for a URL that names no file on this machine: another scheme, or a file URL naming another host
func (*FileURLError) Error ¶
func (e *FileURLError) Error() string
Reason followed by the quoted URL
type Parts ¶
type Parts struct {
Scheme, Authority, Path, Query, Fragment string
}
Components of a URL reference cut at its delimiters, nothing decoded, the scheme lowercased and the authority holding any user info and port
func Split ¶
Reference cut into scheme, authority, path, query and fragment the way RFC 3986 appendix B reads any text, after dropping leading C0 controls and spaces and every tab, CR and LF; an ErrInvalidHost error only for bad IP literal brackets or a non-ASCII authority that NFKC normalization gives URL delimiters
func (Parts) Hostname ¶
Host of the authority, user info and port dropped, IP literal brackets removed, lowercased with an IPv6 zone kept as written