routematch

package
v0.0.0-...-6ed4abe Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2024 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package routematch is for route match operation

Index

Constants

This section is empty.

Variables

View Source
var ErrNoMatched = errors.New("no matched route pattern")

ErrNoMatched no matched route pattern

Functions

This section is empty.

Types

type Route

type Route struct {
	// Method is http method, eg: GET, POST, PUT, DELETE
	Method string
	// Pattern is path pattern, eg: /api/v1/config/biz/{biz_id}/apps/{app_id}
	Pattern string
}

Route is route object

type RouteMatcher

type RouteMatcher struct {
	// contains filtered or unexported fields
}

RouteMatcher is route matcher

func NewRouteMatcher

func NewRouteMatcher(routes []Route) *RouteMatcher

NewRouteMatcher 创建路由匹配器

func (*RouteMatcher) Match

func (m *RouteMatcher) Match(method, path string) (string, error)

Match 获取最长匹配的路由pattern eg: method相同的情况下,/api/v1/config/biz/{biz_id}/apps/{app_id} 可匹配 /api/v1/config/biz/2/apps/1

func (*RouteMatcher) PatternMap

func (m *RouteMatcher) PatternMap() map[string]string

PatternMap return patternMap of RouteMatcher

func (*RouteMatcher) RouteMap

func (m *RouteMatcher) RouteMap() map[string][]string

RouteMap return routemap of RouteMatcher

Jump to

Keyboard shortcuts

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