urly

package module
v0.0.0-...-ff3b3bd Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 21, 2022 License: MIT Imports: 8 Imported by: 0

README

URLy

Golang pkg for URL parsing and normalization. Repository forked from goware/urlx specifically for uncors project.

Changes:

  • Removed defalut http scheme
  • Symbol * allowed in urls

License

URLx is licensed under the MIT License.

Documentation

Overview

Package urly parses and normalizes URLs. It can also resolve hostname to an IP address.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Normalize

func Normalize(u *url.URL) (string, error)

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

func NormalizeString(rawURL string) (string, error)

NormalizeString returns normalized URL string. It's a shortcut for Parse() and Normalize() funcs.

func Parse

func Parse(rawURL string) (*url.URL, error)

Parse parses raw URL string into the net/url URL struct. It uses the url.Parse() internally, but it slightly changes its behavior:

  1. It forces the default scheme and port to http
  2. It favors absolute paths over relative ones, thus "example.com" is parsed into url.Host instead of url.Path.
  3. It lowercases the Host (not only the Scheme).

func ParseWithDefaultScheme

func ParseWithDefaultScheme(rawURL string, scheme string) (*url.URL, error)

func Resolve

func Resolve(u *url.URL) (*net.IPAddr, error)

Resolve resolves the URL host to its IP address.

func ResolveString

func ResolveString(rawURL string) (*net.IPAddr, error)

Resolve resolves the URL host to its IP address. It's a shortcut for Parse() and Resolve() funcs.

func SplitHostPort

func SplitHostPort(u *url.URL) (host, port string, err error)

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.

func URIEncode

func URIEncode(uri string) (string, error)

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL