types

package
v8.1.1 Latest Latest
Warning

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

Go to latest
Published: May 10, 2024 License: MIT Imports: 3 Imported by: 1

Documentation

Overview

Package types 类型的前置声明

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ErrParamNotExists

func ErrParamNotExists() error

ErrParamNotExists 用于表示 Params 中参数不存在的错误

Types

type BuildNodeHandleOf

type BuildNodeHandleOf[T any] func(Node) T

BuildNodeHandleOf 为节点生成处理方法

type Context

type Context struct {
	Path string // 实际请求的路径信息
	// contains filtered or unexported fields
}

Context 保存着路由匹配过程中的上下文关系

Context 同时实现了 Route 接口。

func NewContext

func NewContext() *Context

func (*Context) Bool

func (ctx *Context) Bool(key string) (bool, error)

func (*Context) Count

func (ctx *Context) Count() (cnt int)

func (*Context) Delete

func (ctx *Context) Delete(k string)

func (*Context) Destroy

func (ctx *Context) Destroy()

func (*Context) Exists

func (ctx *Context) Exists(key string) bool

func (*Context) Float

func (ctx *Context) Float(key string) (float64, error)

func (*Context) Get

func (ctx *Context) Get(key string) (string, bool)

func (*Context) Int

func (ctx *Context) Int(key string) (int64, error)

func (*Context) MustBool

func (ctx *Context) MustBool(key string, def bool) bool

func (*Context) MustFloat

func (ctx *Context) MustFloat(key string, def float64) float64

func (*Context) MustInt

func (ctx *Context) MustInt(key string, def int64) int64

func (*Context) MustString

func (ctx *Context) MustString(key, def string) string

func (*Context) MustUint

func (ctx *Context) MustUint(key string, def uint64) uint64

func (*Context) Node

func (ctx *Context) Node() Node

func (*Context) Params

func (ctx *Context) Params() Params

func (*Context) Range

func (ctx *Context) Range(f func(key, val string))

func (*Context) Reset

func (ctx *Context) Reset()

func (*Context) RouterName

func (ctx *Context) RouterName() string

func (*Context) Set

func (ctx *Context) Set(k, v string)

func (*Context) SetNode

func (ctx *Context) SetNode(n Node)

func (*Context) SetRouterName

func (ctx *Context) SetRouterName(n string)

func (*Context) String

func (ctx *Context) String(key string) (string, error)

func (*Context) Uint

func (ctx *Context) Uint(key string) (uint64, error)

type MiddlewareFuncOf

type MiddlewareFuncOf[T any] func(T) T

MiddlewareFuncOf 中间件处理函数

func (MiddlewareFuncOf[T]) Middleware

func (f MiddlewareFuncOf[T]) Middleware(next T) T

type MiddlewareOf

type MiddlewareOf[T any] interface {
	Middleware(T) T
}

MiddlewareOf 中间件对象需要实现的接口

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 表示路由中的参数操作接口

type Route

type Route interface {
	// Params 当前请求关联的参数
	Params() Params

	// Node 当前请求关联的节点信息
	//
	// 有可能返回 nil,比如请求到了 404。
	Node() Node

	// RouterName mux.RouterOf.Name 的值
	RouterName() string
}

Route 当前请求生成的路由信息

Jump to

Keyboard shortcuts

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