urlpattern

package module
v0.0.0-...-334a000 Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2024 License: BSD-3-Clause Imports: 10 Imported by: 0

README

Go URL Pattern

Go Reference Coverage Status

A spec-compliant implementation of the WHATWG URL Pattern Living Standard written in Go.

Tested with web-platform-test test suite.

Docs

Read the docs on Go Packages.

Limitations

Credits

Created by Kévin Dunglas.

Sponsored by:

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

Examples

Constants

This section is empty.

Variables

View Source
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")
)
View Source
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")
)
View Source
var (
	NoBaseURLError             = errors.New("relative URL and no baseURL provided")
	UnexpectedEmptyStringError = errors.New("unexpected empty string")
)
View Source
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

View Source
var TypeError = errors.New("type error")

Functions

This section is empty.

Types

type Options

type Options struct {
	IgnoreCase bool
}

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

https://urlpattern.spec.whatwg.org/#dom-urlpattern-exec

func (*URLPattern) Test

func (u *URLPattern) Test(input, baseURL string) bool

https://urlpattern.spec.whatwg.org/#dom-urlpattern-test

type URLPatternComponentResult

type URLPatternComponentResult struct {
	Input  string
	Groups map[string]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

Jump to

Keyboard shortcuts

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