route

package
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2022 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

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 SysRequest

func SysRequest(proxy *Proxy) interface{}

func View

func View(html string, rew http.ResponseWriter, data web.Context)

Types

type Catch

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

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

type Constructor

type Constructor func(*Proxy) interface{}

type ContentType

type ContentType map[string]string

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

var ResourceMapType ContentType

type Controller

type Controller struct {
	*Proxy
	Context         web.Context     //上下文数据
	UrlVariable     []string        //路径参数,按顺序依次
	RESTFul         map[string]any  // K/V 路径参数 控制器解析中,请求参数参数名尽量不要和 RESTFul 参数同名,否则会覆盖
	InNum           int             //处理器入参参数个数
	OutNum          int             //处理器返回值个数
	InvokeValues    []reflect.Value // InvokeValues存储的是控制器传递参数的序列 按顺序存储每个入参的反射实例
	Args            []string        //参数赋值序列表,主要存储请求参数的只值
	AssignmentIndex []int           //AssignmentIndex 可赋值参数索引序列,可赋值参数序列是存储了系统内部参数之外的请求参数所在 InvokeValues 参数序列中的索引位置。
	ReturnValues    []reflect.Value //返回参数实例
	Fun             reflect.Value   //将被调用的函数,注册阶段已经被构建成为反射类型
	FunType         reflect.Type
	Intrinsic       map[string]web.Variate // 自定赋值参数列表(系统参数配置)
}

func (*Controller) InitArgs

func (control *Controller) InitArgs()

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

type Proxy

type Proxy struct {
	*Router

	Rew        http.ResponseWriter // http 响应体
	Req        *http.Request       // http 请求体
	Middleware []web.Middleware    // 当前控制器待执行中间件
	Context    web.Context         // 请求上下文数据
	File       *web.MultipartFile  // Post文件上传解析值
	Control    Controller          // 待处理执行器

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

	Recover WebRecover // 路由错误捕捉器
	// contains filtered or unexported fields
}

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

type Router

type Router struct {
	web.Log
	MaxMultipartMemory int64
	Root               string                       // 项目更目录
	Resource           string                       // 静态资源管理 默认为 root 目录
	FileService        string                       // 文件服务配置
	ProxyPool          *sync.Pool                   // 创建执行实例
	PathPool           *sync.Pool                   // 分配路径构建
	Catches            map[reflect.Type]Catch       // 全局错误捕捉处理
	Api                map[string][]web.ControlInfo // 接口信息
	Middlewares        []web.Middleware             // 全局中间件
	Controllers        []*reflect.Value             // 存储结构体全局控制器
	DefaultView        web.ViewHandle               // 默认视图处理器,初始化采用 Aurora 实现的函数进行渲染
	Intrinsic          map[string]web.Variate       // 自定义系统参 初始化来自 Engine

	Tree map[string]*node // 路由树根节点
	Mux  *sync.Mutex      // 注册路由并发锁
	// 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, middleware ...web.Middleware)

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

func (*Router) Catch

func (router *Router) Catch(err any)

func (*Router) LoadCache

func (router *Router) LoadCache()

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

func (*Router) Register

func (router *Router) Register(method, path string, control any, middleware ...web.Middleware)

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

func (*Router) ServeHTTP

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

ServeHTTP 一切的开始

func (*Router) Use

func (router *Router) Use(middleware ...web.Middleware)

type ViewHandle

type ViewHandle func(string, http.ResponseWriter, web.Context)

ViewHandle 是整个服务器对视图渲染的核心函数,开发者实现改接口对需要展示的页面进行自定义处理

type WebRecover

type WebRecover func(proxy *Proxy)

WebRecover 用于处理服务器中出现的 panic 消息自定义

Jump to

Keyboard shortcuts

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