13 Star 43 Fork 4

Baa/Baa

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
router.go 1.85 KB
一键复制 编辑 原始数据 按行查看 历史
safeie 提交于 2017-06-28 20:39 . add methods for print route table
package baa
const (
GET int = iota
POST
PUT
DELETE
PATCH
OPTIONS
HEAD
// RouteLength route table length
RouteLength
)
// RouterMethods declare method key in route table
var RouterMethods = map[string]int{
"GET": GET,
"POST": POST,
"PUT": PUT,
"DELETE": DELETE,
"PATCH": PATCH,
"OPTIONS": OPTIONS,
"HEAD": HEAD,
}
// RouterMethodName declare method name with route table key
var RouterMethodName = map[int]string{
GET: "GET",
POST: "POST",
PUT: "PUT",
DELETE: "DELETE",
PATCH: "PATCH",
OPTIONS: "OPTIONS",
HEAD: "HEAD",
}
// Router is an router interface for baa
type Router interface {
// SetAutoHead sets the value who determines whether add HEAD method automatically
// when GET method is added. Combo router will not be affected by this value.
SetAutoHead(v bool)
// SetAutoTrailingSlash optional trailing slash.
SetAutoTrailingSlash(v bool)
// Match find matched route then returns handlers and name
Match(method, uri string, c *Context) ([]HandlerFunc, string)
// URLFor use named route return format url
URLFor(name string, args ...interface{}) string
// Add registers a new handle with the given method, pattern and handlers.
Add(method, pattern string, handlers []HandlerFunc) RouteNode
// GroupAdd registers a list of same prefix route
GroupAdd(pattern string, f func(), handlers []HandlerFunc)
// Routes returns registered route uri in a string slice
Routes() map[string][]string
// NamedRoutes returns named route uri in a string slice
NamedRoutes() map[string]string
}
// RouteNode is an router node
type RouteNode interface {
Name(name string)
}
// IsParamChar check the char can used for route params
// a-z->65:90, A-Z->97:122, 0-9->48->57, _->95
func IsParamChar(c byte) bool {
if (c >= 65 && c <= 90) || (c >= 97 && c <= 122) || (c >= 48 && c <= 57) || c == 95 {
return true
}
return false
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/go-baa/baa.git
git@gitee.com:go-baa/baa.git
go-baa
baa
Baa
master

搜索帮助