fasturl

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2018 License: GPL-2.0 Imports: 4 Imported by: 1

Documentation

Overview

Package fasturl parses URLs and implements query escaping.

Index

Constants

View Source
const (
	SchemeInvalid = iota
	SchemeHTTP
	SchemeHTTPS
	SchemeCount
)

Variables

View Source
var ErrUnknownScheme = errors.New("unknown protocol scheme")
View Source
var Schemes = [SchemeCount]string{
	"",
	"http",
	"https",
}

Functions

func PathUnescape

func PathUnescape(s string) string

Types

type Error

type Error struct {
	Op  string
	URL string
	Err error
}

Error reports an error and the operation and URL that caused it.

func (*Error) Error

func (e *Error) Error() string

func (*Error) Temporary

func (e *Error) Temporary() bool

func (*Error) Timeout

func (e *Error) Timeout() bool

type EscapeError

type EscapeError string

func (EscapeError) Error

func (e EscapeError) Error() string

type InvalidHostError

type InvalidHostError string

func (InvalidHostError) Error

func (e InvalidHostError) Error() string

type Scheme

type Scheme int

type URL

type URL struct {
	Scheme Scheme
	Host   string // host or host:port
	Path   string // path (relative paths may omit leading slash)
}

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, code must not use Path directly. The Parse function sets both Path and RawPath in the URL it returns, and URL's String method uses RawPath if it is a valid encoding of Path, by calling the EscapedPath method.

func (*URL) IsAbs

func (u *URL) IsAbs() bool

IsAbs reports whether the URL is absolute. Absolute means that it has a non-empty scheme.

func (*URL) MarshalBinary

func (u *URL) MarshalBinary() (text []byte, err error)

func (*URL) Parse

func (u *URL) Parse(rawurl string) error

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.

func (*URL) ParseRel

func (u *URL) ParseRel(out *URL, ref string) error

ParseRel 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.

func (*URL) ParseRequestURI

func (u *URL) ParseRequestURI(rawurl string) error

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.)

func (*URL) ResolveReference

func (u *URL) ResolveReference(url *URL, ref *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.

func (*URL) String

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. 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.

func (*URL) UnmarshalBinary

func (u *URL) UnmarshalBinary(text []byte) error

Jump to

Keyboard shortcuts

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