router

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2023 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckValid

func CheckValid(parent *CNode, child *CNode)

CheckValid 检查路由冲突

func ParseParams

func ParseParams(parts []string, searchParts []string) map[string]string

ParseParams 解析路由参数

func ParsePattern

func ParsePattern(pattern string) []string

ParasePattern 解析路由

Types

type CNode

type CNode struct {
	Pattern  string
	Part     string
	Type     TypeNode
	Children []*CNode
}

CNode 路由节点

func NewNode

func NewNode(part string) *CNode

NewNode 构造路由节点

type CNodes

type CNodes []*CNode

CNodes 节点组,用于排序

func (CNodes) Len

func (nodes CNodes) Len() int

func (CNodes) Less

func (nodes CNodes) Less(i, j int) bool

func (CNodes) Swap

func (nodes CNodes) Swap(i, j int)

type CRouter

type CRouter struct {
	Roots map[string]*CNode
}

CRouter 路由

func NewRouter

func NewRouter() *CRouter

NewRouter 构造路由

func (*CRouter) AddRoute

func (router *CRouter) AddRoute(method, pattern string)

AddRoute 添加路由

func (*CRouter) GetRoute

func (router *CRouter) GetRoute(method string, pattern string) (string, map[string]string)

GetRoute 获取路由节点及路由参数

type IRouter

type IRouter interface {
	AddRoute(method, pattern string)                             // 添加路由
	GetRoute(method, pattern string) (string, map[string]string) // 获取路由和路由参数
}

IRouter 路由接口

type TypeNode

type TypeNode int

TypeNode 节点类型

const (
	WildNode     TypeNode = iota // 通配符路由
	DynamicNode                  // 动态路由
	AbsoluteNode                 // 绝对路由
)

func CheckNodeType

func CheckNodeType(part string) TypeNode

CheckNodeType 判断路由节点类型

Jump to

Keyboard shortcuts

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