Documentation ¶
Overview ¶
Package matcher provides a generic map with regex keys, that can be used to match items to paths, e.g. when using middleware.
Index ¶
- type Matcher
- func (m *Matcher[T]) Add(selector, name string, item T)
- func (m *Matcher[T]) AddPlugin(selector, plugin string) error
- func (m Matcher[T]) Len() int
- func (m *Matcher[T]) Match(operation string) []T
- func (m *Matcher[T]) UnmarshalJSON(data []byte) error
- func (m *Matcher[T]) UnmarshalYAML(data *yaml.Node) error
- func (m *Matcher[T]) Use(name string, item T)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Matcher ¶
type Matcher[T any] struct { // contains filtered or unexported fields }
Matcher is a map with regular expressions as keys. It is used to add middleware on a path based level.
In addition to setting regex selectors for each item, they are also de-duplocated with a name key, to make sure each item is only added once.
func NewMatcher ¶
NewMatcher creates a new matcher object.
func (*Matcher[T]) Add ¶
Add will add an item to every item the selector matches. The selector is a regexp.
Example selector:
- /*
- /echo
- /echo/*
- /echo[1-9]
- suffix$
func (*Matcher[T]) UnmarshalJSON ¶
UnmarshalJSON will unmarshal a JSON file into the matcher. JSON can contain either a string or <name, selector> map.
All items provided through the config need to be registered as plugins. All config will add to, not replace the exisiting items.
JSON config example:
{ "middleware":[ "abc", { "name":"def", "selector":"/foo" } ] }
func (*Matcher[T]) UnmarshalYAML ¶
UnmarshalYAML will unmarshal a yaml file into the matcher. Yaml can contain either a string or <name, selector> map.
All items provided through the config need to be registered as plugins. All config will add to, not replace the exisiting items.
Yaml config example:
middleware: - abc - name: def selector: "/foo"