Documentation
¶
Index ¶
- type Context
- func (c *Context) Abort()
- func (c *Context) AbortWithError(err error)
- func (c *Context) AbortWithJSON(code int, obj any)
- func (c *Context) AbortWithStatus(code int)
- func (c *Context) Aborted() bool
- func (c *Context) Context() context.Context
- func (c *Context) Get(key string) (value any, exists bool)
- func (c *Context) JSON(code int, obj any)
- func (c *Context) Next()
- func (c *Context) Param(name string) string
- func (c *Context) Render(code int, r Render)
- func (c *Context) Route() Route
- func (c *Context) Set(key string, value any)
- func (c *Context) Status(code int)
- func (c *Context) String(code int, s string)
- func (c *Context) UseContext(ctx context.Context)
- type Engine
- type ErrorEncoder
- type HandlerFunc
- type HandlersChain
- type Param
- type Params
- type Render
- type ResponseWriter
- type Route
- type Router
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Context ¶
type Context struct {
Request *http.Request
Writer ResponseWriter
Params Params
Keys map[string]any
// contains filtered or unexported fields
}
func (*Context) AbortWithError ¶ added in v0.0.6
func (*Context) AbortWithJSON ¶
func (*Context) AbortWithStatus ¶
func (*Context) UseContext ¶ added in v0.0.7
UseContext 替换当前请求的上下文。
后续的中间件和处理函数通过 Context.Context() 获取到的将是新的上下文, 常用于超时控制、链路追踪等场景。传入 nil 时不做任何修改。
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
func (*Engine) ServeHTTP ¶
func (e *Engine) ServeHTTP(writer http.ResponseWriter, request *http.Request)
func (*Engine) Use ¶
func (e *Engine) Use(middleware ...HandlerFunc)
Use 追加全局中间件。
全局中间件对所有请求生效,按注册顺序依次执行,并且先于路由自身的处理函数。 多次调用会依次累加;需要终止后续处理时调用 Context.Abort。
func (*Engine) UseErrorEncoder ¶ added in v0.0.8
func (e *Engine) UseErrorEncoder(encoder ErrorEncoder)
UseErrorEncoder 设置错误编码器。
请求处理过程中发生错误时,ErrorEncoder 负责把错误转换成响应。 传入 nil 时恢复为默认实现,即返回 500 并输出错误信息。 多次调用以最后一次为准。
func (*Engine) UseNotFoundHandler ¶ added in v0.0.8
func (e *Engine) UseNotFoundHandler(handlers ...HandlerFunc)
UseNotFoundHandler 设置路由未匹配时的兜底处理器。
该处理器只在没有任何路由匹配时执行(即返回 404),并且位于全局中间件之后。 若处理器没有输出任何内容,Engine 会输出默认的 404 提示。 多次调用以最后一次为准。
type ErrorEncoder ¶ added in v0.0.8
type HandlerFunc ¶
type HandlerFunc func(c *Context)
func Logger ¶ added in v0.0.6
func Logger() HandlerFunc
type HandlersChain ¶
type HandlersChain []HandlerFunc
func CombineHandlers ¶ added in v0.0.6
func CombineHandlers(base HandlersChain, handlers ...HandlerFunc) HandlersChain
type Param ¶ added in v0.0.6
type Param struct {
// Key 是规则中声明的参数名,不包含前缀的 : 或 *。
Key string
// Value 是输入路径中被该参数捕获到的原始字符串。
Value string
}
Param 是一次路径匹配得到的单个参数。
type Params ¶ added in v0.0.6
type Params []Param
Params 是按规则中参数出现顺序保存的参数列表。
type ResponseWriter ¶
type ResponseWriter interface {
http.ResponseWriter
http.Hijacker
http.Flusher
// Status returns the HTTP response status code of the current request.
Status() int
// Size returns the number of bytes already written into the response http body.
// See Written()
Size() int
// WriteString writes the string into the response body.
WriteString(string) (int, error)
// Written returns true if the response body was already written.
Written() bool
// WriteHeaderNow forces to write the http header (status code + headers).
WriteHeaderNow()
// Pusher get the http.Pusher for server push
Pusher() http.Pusher
}
ResponseWriter ...
type Route ¶
type Route interface {
Path() string
Handlers() HandlersChain
}
Route 表示 Router 已经匹配到的处理目标。
Source Files
¶
Click to show internal directories.
Click to hide internal directories.