routing

package
v0.0.0-...-cf0249b Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ADD = iota + 1
	USE
	FOR
	GROUP
)
View Source
const SERVE = "SERVE" // Serving static files directive

Variables

Functions

func MethodRouteVersionToPattern

func MethodRouteVersionToPattern(method, route, version string) string

func ParseToParamKey

func ParseToParamKey(str string) (string, map[string][]int)

func PatternToMethodRouteVersion

func PatternToMethodRouteVersion(pattern string) (string, string, string)

func ToEndpoint

func ToEndpoint(str string) string

Types

type Node

type Node map[string]*Trie

type Router

type Router struct {
	*Trie
	Hash               map[string]RouterItem
	List               []string
	GlobalMiddlewares  []ctx.Handler
	InjectableHandlers map[string]any
}

func NewRouter

func NewRouter() *Router

func (*Router) Add

func (r *Router) Add(method, route, version string, handler ctx.Handler) *Router

alway use latest add

func (*Router) AddInjectableHandler

func (r *Router) AddInjectableHandler(method, route, version string, handler any) *Router

func (*Router) For

func (r *Router) For(methodInclusions []string, route string, version string) func(handlers ...ctx.Handler) *Router

func (*Router) Group

func (r *Router) Group(prefix string, subRouters ...*Router) *Router

func (*Router) Match

func (r *Router) Match(method, route, version string) (bool, string, map[string][]int, []string, []ctx.Handler)

func (*Router) Use

func (r *Router) Use(handlers ...ctx.Handler) *Router

type RouterItem

type RouterItem struct {
	Index        int
	HandlerIndex int
	Handlers     []ctx.Handler
	// contains filtered or unexported fields
}

type ScanFn

type ScanFn func(string, *Trie)

type Trie

type Trie struct {
	Children  Node
	Handlers  []ctx.Handler
	ParamKeys map[string][]int
	Index     int
}

func NewTrie

func NewTrie() *Trie

func (*Trie) ToJSON

func (tr *Trie) ToJSON() (string, error)

Jump to

Keyboard shortcuts

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