Documentation ¶
Overview ¶
Package urlx parses and normalizes URLs. It can also resolve hostname to an IP address.
Index ¶
- func Normalize(u *url.URL) (string, error)
- func NormalizeString(rawURL string) (string, error)
- func Parse(rawURL string) (*url.URL, error)
- func ParseWithDefaultScheme(rawURL string, scheme string) (*url.URL, error)
- func Resolve(u *url.URL) (*net.IPAddr, error)
- func ResolveString(rawURL string) (*net.IPAddr, error)
- func SplitHostPort(u *url.URL) (host, port string, err error)
- func URIEncode(uri string) (string, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Normalize ¶
Normalize returns normalized URL string. Behavior: 1. Remove unnecessary host dots. 2. Remove default port (http://localhost:80 becomes http://localhost). 3. Remove duplicate slashes. 4. Remove unnecessary dots from path. 5. Sort query parameters. 6. Decode host IP into decimal numbers. 7. Handle escape values. 8. Decode Punycode domains into UTF8 representation.
func NormalizeString ¶
NormalizeString returns normalized URL string. It's a shortcut for Parse() and Normalize() funcs.
func Parse ¶
Parse parses raw URL string into the net/url URL struct. It uses the url.Parse() internally, but it slightly changes its behavior:
- It forces the default scheme and port to http
- It favors absolute paths over relative ones, thus "example.com" is parsed into url.Host instead of url.Path.
- It lowercases the Host (not only the Scheme).
func ParseWithDefaultScheme ¶
func ResolveString ¶
Resolve resolves the URL host to its IP address. It's a shortcut for Parse() and Resolve() funcs.
func SplitHostPort ¶
SplitHostPort splits network address of the form "host:port" into host and port. Unlike net.SplitHostPort(), it doesn't remove brackets from [IPv6] host and it accepts net/url.URL struct instead of a string.
Types ¶
This section is empty.