matcher

package
v2.12.1-rc.1 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2023 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type HeaderMap added in v2.6.0

type HeaderMap map[string]Value

func (HeaderMap) HeaderMap added in v2.6.0

func (m HeaderMap) HeaderMap() HeaderMap

HeaderMap returns HeaderMap correspondence of this instance.

func (HeaderMap) Map added in v2.6.0

func (m HeaderMap) Map() map[string]string

Map returns the map correspondence of this instance. The returned value can be used as an argument to NewHeaders to create an identical Headers.

func (HeaderMap) Matches added in v2.6.0

func (m HeaderMap) Matches(h http.Header) bool

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.

func (HeaderMap) String added in v2.6.0

func (m HeaderMap) String() string

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

	// HeaderMap returns HeaderMap correspondence of this instance.
	HeaderMap() HeaderMap

	// 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

	// Headers returns Headers of this instance.
	Headers() Headers

	// 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

	// Path returns the path
	Path() Value
}

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(path Value, hm HeaderMap) Request

func NewRequestFromMap added in v2.6.0

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

NewRequestFromMap 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