urlmatcher

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: May 18, 2023 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package urlmatcher defines interface for URL matching.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AndMatcher

type AndMatcher []Matcher

AndMatcher matches the URL u if u matches all of the given Matchers.

An empty AndMatcher matches all URLs.

func AllOf

func AllOf(m ...Matcher) AndMatcher

AllOf creates a new AndMatcher with m.

func (AndMatcher) Match

func (am AndMatcher) Match(u *url.URL) bool

Match calls Matchers in order and returns true if all of them return true. It stops the evaluation and returns false immediately when some Matcher returns false; the subsequent Matchers will not be called (short-circuit).

Match returns true if am is empty.

type Matcher

type Matcher interface {
	Match(u *url.URL) bool
}

Matcher checks whether the given URL meets condition(s).

func HasEscapedPathPrefix

func HasEscapedPathPrefix(prefix string) Matcher

HasEscapedPathPrefix matches the URL u if u.EscapedPath() starts with prefix.

func HasEscapedPathRegexp

func HasEscapedPathRegexp(re *regexp.Regexp) Matcher

HasEscapedPathRegexp matches the URL u if u.EscapedPath() matches the provided Regexp re. Note it just uses re.MatchString to determine the matching, so partial matches are considered as a match. If you want to match your pattern against the entire u.EscapedPath(), enclose it with `\A(?:...)\z`.

func HasHost

func HasHost(host string) Matcher

HasHost matches the URL u if u.Host is equal to host. ASCII letters are compared in a case-insensitive manner as specified in RFC 4343.

Note u.Host may include a port number. To exclude it from matching, use HasHostname instead.

func HasHostname

func HasHostname(hostname string) Matcher

HasHostname matches the URL u if u.Hostname() is equal to hostname. It does not inspect the port number, unlike HasHost. ASCII letters are compared in a case-insensitive manner as specified in RFC 4343.

func HasHostnameSuffix

func HasHostnameSuffix(suffix string) Matcher

HasHostnameSuffix matches the URL u if u.Hostname() ends with suffix. If suffix has a leading dot ("."), the Matcher matches strictly the subdomains. Otherwise the Matcher matches the exact domain as well. In either case, the Matcher does not match any domains which are not a subdomain of suffix. For example:

  • ".example.com" matches "www.example.com" but not "example.com".
  • "example.com" matches both "www.example.com" and "example.com".
  • Neither ".example.com" nor "exmple.com" matches "counterexample.com".

ASCII letters are compared in a case-insensitive manner as specified in RFC 4343.

func HasRawQueryRegexp

func HasRawQueryRegexp(re *regexp.Regexp) Matcher

HasRawQueryRegexp matches the URL u if u.RawQuery matches the provided Regexp re. Note it just uses re.MatchString to determine the matching, so partial matches are considered as a match. If you want to match your pattern against the entire u.RawQuery, enclose it with `\A(?:...)\z`.

func HasScheme

func HasScheme(scheme string) Matcher

HasScheme matches the URL u if u.Scheme is equal to scheme.

type MatcherFunc

type MatcherFunc func(*url.URL) bool

MatcherFunc turns an ordinary function into a Matcher. If f is a function with the appropriate signature, MatcherFunc(f) is a Matcher calling f.

func (MatcherFunc) Match

func (f MatcherFunc) Match(u *url.URL) bool

Match calls f(u).

type NotMatcher

type NotMatcher struct{ M Matcher }

NotMatcher negates the Matcher M.

func Not

func Not(m Matcher) NotMatcher

Not returns a Matcher that negates m.

func (NotMatcher) Match

func (neg NotMatcher) Match(u *url.URL) bool

Match returns true if neg.M.Match(u) returns false.

type OrMatcher

type OrMatcher []Matcher

OrMatcher matches the URL u if u matches at least one of the given Matchers.

An empty OrMatcher matches no URLs.

func AnyOf

func AnyOf(m ...Matcher) OrMatcher

AnyOf creates a new OrMatcher with m.

func (OrMatcher) Match

func (om OrMatcher) Match(u *url.URL) bool

Match calls Matchers in order and returns true if some Matcher returns true. It stops the evaluation immediately once it finds a matching; the subsequent Matchers will not be called (short-circuit).

Match returns false if om is empty.

Jump to

Keyboard shortcuts

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