Documentation
¶
Index ¶
- Constants
- type Context
- func (c *Context) AllUrlPathParam() map[string]string
- func (c *Context) GetContextValue(key any) any
- func (c *Context) GetUrlPathParam(key string) string
- func (c *Context) ReadJSON(v any) error
- func (c *Context) SetContextValue(key any, value any)
- func (c *Context) Stop()
- func (c *Context) WriteJSON(v any, statusCode ...int) error
- type GOweb
- func (g *GOweb) GetValue(key any) any
- func (g *GOweb) NoRoute(handlerFunc HandlerFunc)
- func (g *GOweb) Run(addr string) error
- func (g *GOweb) RunTLS(addr, certFile, keyFile string) error
- func (g *GOweb) ServeHTTP(writer http.ResponseWriter, request *http.Request)
- func (g *GOweb) SetValue(key, value any)
- type HandlerFunc
- type Option
- type RouterGroup
- func (g *RouterGroup) Any(path string, handlerFunc HandlerFunc)
- func (g *RouterGroup) BottomNodeList() []*RouterGroup
- func (g *RouterGroup) CONNECT(path string, handlerFunc HandlerFunc)
- func (g *RouterGroup) DELETE(path string, handlerFunc HandlerFunc)
- func (g *RouterGroup) FootMiddleware(handlers ...HandlerFunc)
- func (g *RouterGroup) GET(path string, handlerFunc HandlerFunc)
- func (g *RouterGroup) Grep(path string) *RouterGroup
- func (g *RouterGroup) HEAD(path string, handlerFunc HandlerFunc)
- func (g *RouterGroup) HeadMiddleware(handlers ...HandlerFunc)
- func (g *RouterGroup) List() (methods, paths []string)
- func (g *RouterGroup) OPTIONS(path string, handlerFunc HandlerFunc)
- func (g *RouterGroup) POST(path string, handlerFunc HandlerFunc)
- func (g *RouterGroup) PUT(path string, handlerFunc HandlerFunc)
- func (g *RouterGroup) PathMatch(path, method string) (params map[string]string, handle HandlerFunc, grep *RouterGroup)
Constants ¶
View Source
const ( GET = "GET" POST = "POST" DELETE = "DELETE" PUT = "PUT" HEAD = "HEAD" OPTIONS = "OPTIONS" CONNECT = "CONNECT" ANY = "ANY" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Context ¶
type Context struct {
Request *http.Request
Writer http.ResponseWriter
context.Context
// contains filtered or unexported fields
}
func (*Context) AllUrlPathParam ¶
func (*Context) GetContextValue ¶
func (*Context) GetUrlPathParam ¶
func (*Context) SetContextValue ¶
type GOweb ¶
type GOweb struct {
RouterGroup
context.Context
// contains filtered or unexported fields
}
func (*GOweb) NoRoute ¶
func (g *GOweb) NoRoute(handlerFunc HandlerFunc)
type HandlerFunc ¶
type HandlerFunc func(ctx *Context)
type RouterGroup ¶
type RouterGroup struct {
// contains filtered or unexported fields
}
RouterGroup 是段级压缩前缀树(radix tree)的节点。
一条边由若干「路径段」组成,存放于 segments:
- kindStatic : 普通段链,如 ["api","v1","users"]
- kindParam : 单段,形如 ["#name"]
- kindCatchAll : 单段 ["#..."]
同一节点同时最多拥有:
- 任意多个静态子节点(按首段分桶到 staticKids)
- 至多一个 paramKid(不同名字会冲突)
- 至多一个 catchAllKid
匹配优先级:staticKids > paramKid > catchAllKid。
写端节点:host != nil;可在该节点上调用注册 API。 快照节点:host == nil;只读,注册 API 会 panic(防止误改快照)。
func (*RouterGroup) Any ¶
func (g *RouterGroup) Any(path string, handlerFunc HandlerFunc)
func (*RouterGroup) BottomNodeList ¶
func (g *RouterGroup) BottomNodeList() []*RouterGroup
BottomNodeList 返回不含任何子节点的叶子节点(写端视图)。
注意:仅在「注册阶段已完成」或调用方自行同步时使用;与并发注册混用会产生竞态。
func (*RouterGroup) CONNECT ¶
func (g *RouterGroup) CONNECT(path string, handlerFunc HandlerFunc)
func (*RouterGroup) DELETE ¶
func (g *RouterGroup) DELETE(path string, handlerFunc HandlerFunc)
func (*RouterGroup) FootMiddleware ¶
func (g *RouterGroup) FootMiddleware(handlers ...HandlerFunc)
FootMiddleware 尾部中间件,在路由 handler 之后运行。
func (*RouterGroup) GET ¶
func (g *RouterGroup) GET(path string, handlerFunc HandlerFunc)
func (*RouterGroup) Grep ¶
func (g *RouterGroup) Grep(path string) *RouterGroup
Grep 取或创建 path 对应的子节点,便于在该位置挂载中间件 / 子路由。 若 path 落在某条压缩边的中段,会自动从该边分裂出对应节点。
func (*RouterGroup) HEAD ¶
func (g *RouterGroup) HEAD(path string, handlerFunc HandlerFunc)
func (*RouterGroup) HeadMiddleware ¶
func (g *RouterGroup) HeadMiddleware(handlers ...HandlerFunc)
HeadMiddleware 头部中间件,在路由 handler 之前运行。
func (*RouterGroup) List ¶
func (g *RouterGroup) List() (methods, paths []string)
List 列出所有已注册的路由(包括非叶子节点上的);输出按 (path, method) 字典序排序。
func (*RouterGroup) OPTIONS ¶
func (g *RouterGroup) OPTIONS(path string, handlerFunc HandlerFunc)
func (*RouterGroup) POST ¶
func (g *RouterGroup) POST(path string, handlerFunc HandlerFunc)
func (*RouterGroup) PUT ¶
func (g *RouterGroup) PUT(path string, handlerFunc HandlerFunc)
func (*RouterGroup) PathMatch ¶
func (g *RouterGroup) PathMatch(path, method string) (params map[string]string, handle HandlerFunc, grep *RouterGroup)
PathMatch 是公开 API:基于已发布的快照做匹配。当前 RouterGroup 不在 任何 registry 下(裸节点 / 快照节点)时返回 (nil, nil, nil)。
ServeHTTP 不直接走这里,而是直接使用 snapshot.match 以拿到 Allow 信息。
Click to show internal directories.
Click to hide internal directories.