Documentation
¶
Overview ¶
Package urlpattern implements the URLPattern web API.
The specification is available at https://urlpattern.spec.whatwg.org/.
Example ¶
pattern, err := urlpattern.New("/books/:id", "https://example.com", nil) if err != nil { panic(err) } fmt.Printf("%t\n", pattern.Test("https://example.com/books/123", "")) fmt.Printf("%t\n", pattern.Test("https://example.com/authors/123", "")) fmt.Printf("%v", pattern.Exec("123", "https://example.com/books/").Pathname.Groups)
Output: true false map[id:123]
Index ¶
- Variables
- type Options
- type URLPattern
- func (u *URLPattern) Exec(input, baseURLString string) *URLPatternResult
- func (u *URLPattern) ExecInit(input *URLPatternInit) *URLPatternResult
- func (u *URLPattern) HasRegexpGroups() bool
- func (u *URLPattern) Hash() string
- func (u *URLPattern) Hostname() string
- func (u *URLPattern) Password() string
- func (u *URLPattern) Pathname() string
- func (u *URLPattern) Port() string
- func (u *URLPattern) Protocol() string
- func (u *URLPattern) Search() string
- func (u *URLPattern) Test(input, baseURL string) bool
- func (u *URLPattern) TestInit(input *URLPatternInit) bool
- func (u *URLPattern) Username() string
- type URLPatternComponentResult
- type URLPatternInit
- type URLPatternResult
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ( NonEmptySuffixError = errors.New("suffix must be the empty string") BadParserIndexError = errors.New("parser's index must be less than parser's token list size") DuplicatePartNameError = errors.New("duplicate name") RequiredTokenError = errors.New("missing required token") InvalidIPv6HostnameError = errors.New("invalid IPv6 hostname") InvalidPortError = errors.New("invalid port") )
var ( EmptyPartNameError = errors.New("part's name must not be empty string") InvalidModifierError = errors.New(`part's modifier must be "zero-or-more" or "one-or-more"`) InvalidPrefixOrSuffix = errors.New("part's prefix is not the empty string or part's suffix is not the empty string") InvalidPartNameError = errors.New("part's name is not the empty string or null") )
var ( NoBaseURLError = errors.New("relative URL and no baseURL provided") UnexpectedEmptyStringError = errors.New("unexpected empty string") )
var DefaultPorts = map[string]string{
"http": "80",
"https": "443",
"ws": "80",
"wss": "443",
"ftp": "21",
}
Experimental: this symbol is exported to allow users adding new values, but may be removed in the feature. TODO: there is nothing in the Go stdlib to find the default port associated with a protocol. Let's just replace values for protocols in specialSchemeList for now. This list could be completed using https://en.wikipedia.org/wiki/List_of_TCP_and_UDP_port_numbers
var TypeError = errors.New("type error")
Functions ¶
This section is empty.
Types ¶
type URLPattern ¶
type URLPattern struct {
// contains filtered or unexported fields
}
https://urlpattern.spec.whatwg.org/#url-pattern-struct
func (*URLPattern) Exec ¶
func (u *URLPattern) Exec(input, baseURLString string) *URLPatternResult
func (*URLPattern) ExecInit ¶
func (u *URLPattern) ExecInit(input *URLPatternInit) *URLPatternResult
func (*URLPattern) HasRegexpGroups ¶
func (u *URLPattern) HasRegexpGroups() bool
https://urlpattern.spec.whatwg.org/#url-pattern-has-regexp-groups
func (*URLPattern) Hash ¶
func (u *URLPattern) Hash() string
func (*URLPattern) Hostname ¶
func (u *URLPattern) Hostname() string
func (*URLPattern) Password ¶
func (u *URLPattern) Password() string
func (*URLPattern) Pathname ¶
func (u *URLPattern) Pathname() string
func (*URLPattern) Port ¶
func (u *URLPattern) Port() string
func (*URLPattern) Protocol ¶
func (u *URLPattern) Protocol() string
func (*URLPattern) Search ¶
func (u *URLPattern) Search() string
func (*URLPattern) Test ¶
func (u *URLPattern) Test(input, baseURL string) bool
func (*URLPattern) TestInit ¶
func (u *URLPattern) TestInit(input *URLPatternInit) bool
func (*URLPattern) Username ¶
func (u *URLPattern) Username() string
type URLPatternInit ¶
type URLPatternInit struct { Protocol *string Username *string Password *string Hostname *string Port *string Pathname *string Search *string Hash *string BaseURL *string }
https://urlpattern.spec.whatwg.org/#dictdef-urlpatterninit
func (*URLPatternInit) New ¶
func (init *URLPatternInit) New(opt *Options) (*URLPattern, error)
type URLPatternResult ¶
type URLPatternResult struct { Inputs []string InitInputs []*URLPatternInit Protocol URLPatternComponentResult Username URLPatternComponentResult Password URLPatternComponentResult Hostname URLPatternComponentResult Port URLPatternComponentResult Pathname URLPatternComponentResult Search URLPatternComponentResult Hash URLPatternComponentResult }