Documentation
¶
Overview ¶
Package types 类型的前置声明
Index ¶
- func ErrParamNotExists() error
- type BuildNodeHandler
- type Context
- func (ctx *Context) Bool(key string) (bool, error)
- func (ctx *Context) Count() int
- func (ctx *Context) Delete(k string)
- func (ctx *Context) Destroy()
- func (ctx *Context) Exists(key string) bool
- func (ctx *Context) Float(key string) (float64, error)
- func (ctx *Context) Get(key string) (string, bool)
- func (ctx *Context) Int(key string) (int64, error)
- func (ctx *Context) MustBool(key string, def bool) bool
- func (ctx *Context) MustFloat(key string, def float64) float64
- func (ctx *Context) MustInt(key string, def int64) int64
- func (ctx *Context) MustString(key, def string) string
- func (ctx *Context) MustUint(key string, def uint64) uint64
- func (ctx *Context) Node() Node
- func (ctx *Context) Params() Params
- func (ctx *Context) Range(f func(key, val string))
- func (ctx *Context) Reset()
- func (ctx *Context) RouterName() string
- func (ctx *Context) Set(k, v string)
- func (ctx *Context) SetNode(n Node)
- func (ctx *Context) SetRouterName(n string)
- func (ctx *Context) String(key string) (string, error)
- func (ctx *Context) Uint(key string) (uint64, error)
- type Middleware
- type MiddlewareFunc
- type Node
- type Params
- type Route
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Context ¶
type Context struct {
Path string // 实际请求的路径信息
// contains filtered or unexported fields
}
Context 保存着路由匹配过程中的上下文关系
Context 同时实现了 Route 接口。
func NewContext ¶
func NewContext() *Context
func (*Context) MustString ¶
func (*Context) RouterName ¶
func (*Context) SetRouterName ¶
type Middleware ¶
type Middleware[T any] interface { // Middleware 调整路由项 next 的行为 // // next 路由项的处理函数; // method 当前路由的请求方法; // pattern 当前路由的匹配项; // router 路由名称,即 [mux.Router.Name] 的值; // // NOTE: method 和 pattern 在某些特殊的路由项中会有特殊的值: // - 404 method 和 pattern 均为空; // - 405 method 为空,pattern 正常; // - TRACE 请求则 pattern 为空; // // NOTE: 此方法本身仅执行一次,返回的对象才会在每次请求时都执行。 Middleware(next T, method, pattern, router string) T }
Middleware 中间件
type MiddlewareFunc ¶
MiddlewareFunc 中间件
func (MiddlewareFunc[T]) Middleware ¶
func (f MiddlewareFunc[T]) Middleware(next T, method, pattern, router string) T
type Node ¶
type Node interface {
// Pattern 路由上的匹配内容
Pattern() string
// Methods 当前节点支持的方法列表
Methods() []string
// AllowHeader Allow 报头的内容
AllowHeader() string
}
Node 路由节点
type Params ¶
type Params interface {
// Count 返回参数的数量
Count() int
// Get 获取指定名称的参数值
Get(key string) (v string, found bool)
// Exists 查找指定名称的参数是否存在
Exists(key string) bool
// String 获取地址参数中的名为 key 的变量并将其转换成 string
//
// 当参数不存在时,返回 [ErrParamNotExists] 错误。
String(key string) (string, error)
// MustString 获取地址参数中的名为 key 的变量并将其转换成 string
//
// 若不存在或是无法转换则返回 def。
MustString(key, def string) string
// Int 获取地址参数中的名为 key 的变量并将其转换成 int64
//
// 当参数不存在时,返回 [ErrParamNotExists] 错误。
Int(key string) (int64, error)
// MustInt 获取地址参数中的名为 key 的变量并将其转换成 int64
//
// 若不存在或是无法转换则返回 def。
MustInt(key string, def int64) int64
// Uint 获取地址参数中的名为 key 的变量并将其转换成 uint64
//
// 当参数不存在时,返回 [ErrParamNotExists] 错误。
Uint(key string) (uint64, error)
// MustUint 获取地址参数中的名为 key 的变量并将其转换成 uint64
//
// 若不存在或是无法转换则返回 def。
MustUint(key string, def uint64) uint64
// Bool 获取地址参数中的名为 key 的变量并将其转换成 bool
//
// 当参数不存在时,返回 [ErrParamNotExists] 错误。
Bool(key string) (bool, error)
// MustBool 获取地址参数中的名为 key 的变量并将其转换成 bool
//
// 若不存在或是无法转换则返回 def。
MustBool(key string, def bool) bool
// Float 获取地址参数中的名为 key 的变量并将其转换成 Float64
//
// 当参数不存在时,返回 [ErrParamNotExists] 错误。
Float(key string) (float64, error)
// MustFloat 获取地址参数中的名为 key 的变量并将其转换成 float64
//
// 若不存在或是无法转换则返回 def。
MustFloat(key string, def float64) float64
// Set 添加或是修改值
Set(key, val string)
// Range 依次访问每个参数
Range(func(key, val string))
}
Params 表示路由中的参数操作接口
Click to show internal directories.
Click to hide internal directories.