matcher

package
v0.0.0-...-86535e8 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2019 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package matcher exposes the main interfaces and structs that can be used to test `eskip` routes.

Example
m, err := New(&Options{
	RoutesFile: "./testdata/routes.eskip",
})

if err != nil {
	log.Fatal(err)
	return
}

result := m.Test(&RequestAttributes{
	Method: "GET",
	Path:   "/bar",
	Headers: map[string]string{
		"Accept": "application/json",
	},
})

route := result.Route()

if route != nil {
	fmt.Println(route.Id)
	
Output:

bar

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Matcher

type Matcher interface {
	// Given request attributes test if a route matches
	Test(attributes *RequestAttributes) TestResult
}

Matcher helps testing eskip routing logic

func New

func New(o *Options) (Matcher, error)

New create a new Matcher

type Options

type Options struct {
	// Path to a .eskip file defining routes
	RoutesFile string

	// CustomPredicates list of of custom Skipper predicate specs
	CustomPredicates []routing.PredicateSpec

	// CustomFilters lister of custom Skipper filter specs
	CustomFilters []filters.Spec

	// MockFilters list of custom Skipper filters to mock by name
	MockFilters []string

	// IgnoreTrailingSlash Skipper option
	IgnoreTrailingSlash bool

	// Verbose verbose debug output
	Verbose bool
}

Options when creating a NewMatcher

type RequestAttributes

type RequestAttributes struct {
	Method  string
	Path    string
	Headers map[string]string
}

RequestAttributes represents the http request attributes to test

type TestResult

type TestResult interface {
	// Matching route if there was match nil if no match
	Route() *eskip.Route
	// The http request that was used to perform the test
	Request() *http.Request
	// Normalized request attributes after test
	Attributes() *RequestAttributes
	// Nice string representation
	PrettyPrint() string
	// Nice string representation line by line
	PrettyPrintLines() []string
}

TestResult result of a Matcher.Test operation

Jump to

Keyboard shortcuts

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