matcher

package
v2.5.6-rc.1 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2022 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type HeaderStringer

type HeaderStringer http.Header

HeaderStringer turns a http.Header into a fmt.Stringer. It is useful when it's desired to defer string formatting of the header depending on loglevel, for instance:

dlog.Debugf(c, "Header = %s", HeaderStringer(header))

would not perform the actual formatting unless the loglevel is DEBUG or higher.

func (HeaderStringer) String

func (s HeaderStringer) String() string

String formats the Header to a readable multi-line string.

type Headers

type Headers interface {
	// Map returns the map correspondence of this instance. The returned value can be
	// used as an argument to NewHeaders to create an identical Headers.
	Map() map[string]string

	// Matches returns true if all Value matchers in this instance are matched by the given http.Header.
	// Header name comparison is made using the textproto.CanonicalMIMEHeaderKey form of the keys.
	Matches(header http.Header) bool
}

Headers uses a set of Value matchers to match a http.Header

func NewHeaders

func NewHeaders(hs map[string]string) (Headers, error)

NewHeaders creates a new Headers.

type Request

type Request interface {
	fmt.Stringer

	// Map returns the map correspondence of this instance. The returned value can be
	// used as an argument to NewRequest to create an identical Request.
	Map() map[string]string

	// Matches returns true if both the path Value matcher and the Headers matcher in this instance are
	// matched by the given http.Request.
	Matches(path string, headers http.Header) bool
}

The Request matcher uses a Value matcher and a Headers matcher to match the path and headers of a http request

func NewRequest

func NewRequest(m map[string]string) (Request, error)

NewRequest creates a new Request based on the values of the given map. Aside from http headers, the map may contain one of three special keys.

:path-equal: path will match if equal to the value
:path-prefix: path will match prefixed by the value
:path-regex: path will match it matches the regexp value

type Value

type Value interface {
	fmt.Stringer

	// Matches returns true if the given string matches this Value
	Matches(value string) bool

	// Op returns either ==, =~, or prefix
	Op() string
}

Value comes in three flavors. One that performs an exact match against a string, one that uses a regular expression, and one that uses prefix matching.

func NewEqual

func NewEqual(v string) Value

NewEqual returns a Value that is an equal matcher.

func NewPrefix

func NewPrefix(v string) Value

NewPrefix returns a Value that is a prefix matcher.

func NewRegex

func NewRegex(v string) (Value, error)

NewRegex returns a Value that is a regexp matcher. An error is returned if the string cannot be compiled into a regexp.

func NewValue

func NewValue(v string) (Value, error)

NewValue returns a Value that is either an exact or a regexp matcher. The latter is chosen when the given string contains regexp meta characters. An error is returned if the string contains meta characters but cannot be compiled into a regexp.

Jump to

Keyboard shortcuts

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