route

package
v1.3.24 Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2023 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultType = iota
	RESTFulType
)

Variables

This section is empty.

Functions

func ErrorMsg

func ErrorMsg(err error, msg ...string)

func GetRequest

func GetRequest(request *http.Request, control *Controller) []string

func PostRequest

func PostRequest(request *http.Request, control *Controller) []string

func RESTFul added in v1.3.2

func RESTFul(n *Node, mapping string) ([]string, map[string]any)

RESTFul 解析路径参数 n 路由节点 mapping 前端请求路径

Types

type Catch

type Catch struct {
	// contains filtered or unexported fields
}

Catch 错误捕捉器的存储上要进行封装

type ContentType

type ContentType map[string]string

ContentType 定义一个静态资源头类型

var ResourceMapType ContentType

type Controller

type Controller struct {
	*Proxy
	Constraints map[string]web.Verify
	// Context 上下文数据
	Context web.Context
	// UrlVariable 路径参数,按顺序依次
	UrlVariable []string
	// K/V 路径参数 控制器解析中,请求参数参数名尽量不要和 RESTFul 参数同名,否则会覆盖
	RESTFul map[string]any
	// InNum 处理器入参参数个数
	InNum int
	// OutNum 处理器返回值个数
	OutNum int
	// InvokeValues 存储的是控制器传递参数的序列 按顺序存储每个入参的反射实例
	InvokeValues []reflect.Value
	// Args 参数赋值序列表,主要存储请求参数的只值, Args 和 InvokeValues 的元素是一一对应的
	Args []string

	// AssignmentIndex 可赋值参数索引序列
	// 可赋值参数序列是存储了系统内部参数之外的请求参数所在 InvokeValues 参数序列中的索引位置。
	AssignmentIndex []int
	// ReturnValues 返回参数实例
	ReturnValues []reflect.Value
	Fun          reflect.Value //将被调用的函数,注册阶段已经被构建成为反射类型
	FunType      reflect.Type

	// Intrinsic 自定赋值参数列表(包括系统参数配置)
	Intrinsic map[string]web.Variate
}

func (*Controller) InitArgs

func (control *Controller) InitArgs()

InitArgs 初始化参数信息,注册函数阶段调用 完成对 InvokeValues 控制器参数的初始化(未赋值状态) 完成对应的 AssignmentIndex 可赋值参数序列初始化

type Node added in v1.3.15

type Node struct {
	Path     string //当前节点路径
	FullPath string //当前处理器全路径
	NodeType int    //节点类型
	Count    int    //路径数量

	Control *Controller //服务处理函数
	Child   []*Node     //子节点
	// contains filtered or unexported fields
}

Node 路由节点

type Proxy

type Proxy struct {
	*Router
	Rew     http.ResponseWriter // http 响应体
	Req     *http.Request       // http 请求体
	Inter   []web.Interceptor   // 拦截器
	Context web.Context         // 请求上下文数据
	File    *web.MultipartFile  // Post文件上传解析值
	Control Controller          // 待处理执行器

	UrlVariable []string       // RESTFul  顺序值
	RESTFul     map[string]any // RESTFul  K/V值

	Recover web.Recover // 路由错误捕捉器
	Status  int         // 解析 values 后需要响应的具体 http状态码
	Data    []byte      // 解析 values 后需要响应的具体数据
	Error   error       //错误消息
	// contains filtered or unexported fields
}

Proxy 主要完成 接口调用 和 处理响应

type Route added in v1.3.15

type Route interface {

	// Search 方法 参数 root:根路由 ,path:接口请求路径
	// 返回值 *Node: 接口执行节点  []string:请求路径RESTFul参数序列  map[string]any: 请求参数RESTFul k/v
	Search(root *Node, path string) (*Node, []string, map[string]any)
}

type Router

type Router struct {
	*zap.Logger
	Cors web.CorsHandle

	Recovers           web.Recover // 错误捕捉
	MaxMultipartMemory int64       // 文件上传大小
	Root               string      // 项目根目录
	Resource           string      // 静态资源管理 默认为 root 目录

	FileService string                       // 文件服务配置
	ProxyPool   *sync.Pool                   // 创建执行实例
	Catches     map[reflect.Type]Catch       // 全局错误捕捉处理 弃用
	Api         map[string][]web.ControlInfo // 接口信息
	Constraints map[string]web.Verify        // 自定义参数校验器
	Interceptor []web.Interceptor
	Controllers []*reflect.Value       // 存储结构体全局控制器
	DefaultView web.ViewHandle         // 默认视图处理器,初始化采用 web包 的函数进行渲染
	Intrinsic   map[string]web.Variate // 自定义系统参 初始化来自 Engine

	Tree map[string]*Node // 路由树根节点
	Mux  *sync.Mutex      // 注册路由并发锁
	validator.Validate
	// contains filtered or unexported fields
}

Router Aurora 核心路由器

func New

func New() *Router

func (*Router) Cache

func (router *Router) Cache(method string, url string, control any, interceptor ...web.Interceptor)

Cache 通用注册器,封装接口信息到缓存中

func (*Router) Catch

func (router *Router) Catch(err any)

func (*Router) Constraint added in v1.3.5

func (router *Router) Constraint(tag string, verify web.Verify)

Constraint 自定义约束注册

func (*Router) DefaultRoute added in v1.3.15

func (router *Router) DefaultRoute(route Route)

DefaultRoute 使用自定义 路由规则 需要实现 Route 接口

func (*Router) FileServer added in v1.3.9

func (router *Router) FileServer(path string)

func (*Router) Interceptors added in v1.3.17

func (router *Router) Interceptors(interceptors ...web.Interceptor)

func (*Router) LoadCache

func (router *Router) LoadCache()

LoadCache 加载缓存中的接口进行注册到路由

func (*Router) Recover added in v1.3.7

func (router *Router) Recover(webRecover web.Recover)

func (*Router) Register

func (router *Router) Register(method, path string, control any, interceptor ...web.Interceptor)

Register 预处理被添加路径 method: 请求类型 path :注册路径 control : 处理器(需要传递函数) middleware : 路径中间件

func (*Router) Search added in v1.3.15

func (router *Router) Search(root *Node, path string) (*Node, []string, map[string]any)

Search 路由树查询

func (*Router) ServeHTTP

func (router *Router) ServeHTTP(rw http.ResponseWriter, req *http.Request)

ServeHTTP 一切的开始

func (*Router) Static added in v1.3.9

func (router *Router) Static(fs embed.FS)

Jump to

Keyboard shortcuts

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