router

package
v1.1.16 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2022 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const ContextRouteKey = "ContextRouteKey"

ContextRouteKey is a key for storing route information into the request context

Variables

This section is empty.

Functions

func AddRoute

func AddRoute(router *dynamicRouter) func(path, pathPrefix string, methods []string, handler http.Handler) (string, error)

AddRoute adds a new route

func GetHandler

func GetHandler(router *dynamicRouter) http.Handler

GetHandler returns the router http.Handler

func GorillaMuxRouteMatcher

func GorillaMuxRouteMatcher(route Route) func(request *http.Request) RouteMatch

GorillaMuxRouteMatcher is used for route matching

func MatchRoute

func MatchRoute(routes *sync.Map, request *http.Request) (Route, RouteMatch)

MatchRoute checks all the route if they match the incoming request

func NewDynamicRouter

func NewDynamicRouter(routeMatcher RouteMatcherFunc, loggerFactory log.Factory) *dynamicRouter

NewDynamicRouter creates a new dynamic router Its dynamic because it can add/remove routes at runtime this router does not do any route matching, it relies on third parties for that

func RemoveRoute

func RemoveRoute(router *dynamicRouter) func(routeId string)

RemoveRoute removes a route

Types

type Route

type Route struct {
	UID        string
	Path       string
	PathPrefix string
	Methods    []string
	Timeout    time.Duration
	// contains filtered or unexported fields
}

Route stores the information about a certain route

func (Route) String

func (r Route) String() string

type RouteContext

type RouteContext struct {
	Path       string
	PathPrefix string
	Timeout    time.Duration
	Vars       map[string]string
}

RouteContext is the object that gets stored into the request context

func GetRouteContextFromRequestContext added in v1.1.1

func GetRouteContextFromRequestContext(ctx context.Context) (RouteContext, bool)

type RouteMatch

type RouteMatch struct {
	Matched bool
	Vars    map[string]string
}

RouteMatch is the result of a route matching

type RouteMatcherFunc

type RouteMatcherFunc func(route Route) func(request *http.Request) RouteMatch

RouteMatcherFunc type signature that any route matcher have to implement

Jump to

Keyboard shortcuts

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