Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NormalizePort ¶
func NormalizePort(u *url.URL, preferExplicitPort bool, schemeDefaultPorts func(scheme string) int) error
NormalizePort normalizes the port of u. If u's port is a named port then an error is returned. If u's port is the default port for scheme u.Scheme and preferExplicitPort is false then u's port is removed. If u does not have a port and preferExplicitPort is true then u's port is set to the default port for scheme u.Scheme. The default port for scheme x is defined by schemeDefaultPorts(x). If schemeDefaultPorts does not define a port of scheme x then it should return -1. If schemeDefaultPorts(u.Scheme) < 0 then NormalizePort returns an error (because the default port is undefined). If schemeDefaultPorts is nil then NormalizePort behaves as if schemeDefaultPorts is set to SchemeDefaultPorts. If u is not absolute then NormalizePort does not modify u.
func SchemeDefaultPorts ¶
SchemeDefaultPorts returns the default port for scheme s. If no default port is defined for scheme s then returns -1.
func ValidateURL ¶
func ValidateURL(s string, opts ValidateURLOptions) (*url.URL, error)
ValidateURL parses and validates a URI/URL. Let u be the *url.URL as defined by url.Parse(s). ValidateURL returns u if and only if no error occurs. If opts.Abs != nil and u.IsAbs() != *opts.Abs then an error is returned. If len(opts.AllowedSchemes) > 0 and !u.IsAbs() and u.Scheme is not in opts.AllowedSchemes then an error is returned. If opts.NormalizePort != nil then:
- ValidateURL calls NormalizePort(u, *opts.NormalizePort, opts.SchemeDefaultPorts).
- ValidateURL considers named ports invalid and if u.IsAbs() and u.Port() is not an integer then an error is returned.
If opts.StripPathTrailingSlashes then the longest trailing sequence of forward slashes is trimmed from u.Path and u.RawPath.
Unless opts.StripPathTrailingSlashesNoPercentEncoded is true, percent encoded forward slashes are also included in this sequence.
For other options see source code.
Types ¶
type ValidateURLOptions ¶
type ValidateURLOptions struct {
Abs *bool
AllowedSchemes []string
NormalizePort *bool
SchemeDefaultPorts func(scheme string) int
StripFragment bool
StripQuery bool
StripPathTrailingSlashes bool
StripPathTrailingSlashesNoPercentEncoded bool
StripUser bool
StripUserPassword bool
User *bool
UserPassword *bool
}
ValidateURLOptions represents a set of URL validation options accepted by ValidateURL.