tsing

package module
v0.7.2 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2019 License: BSD-3-Clause Imports: 12 Imported by: 2

README

Tsing

原dxvgef/httpdispatcher项目已更名为Tsing

使用Go语言开发,基于高性能的julienschmidt/httprouter路由包实现的HTTP调度器,与net/http标准包配合使用。

没有对httprouter包做任何修改,仅轻量封装实现了更多功能,同时保留net/http标准包的API访问,高度可定制性,非常适合自行整合第三方包进行二次开发扩展功能。

dxvgef/tsing-demo是一个基于Tsing 整合常见功能的完整示例,可以做为项目初始化使用

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type App

type App struct {
	Config AppConfig    // 配置
	Router *RouterGroup // 路由器
	// contains filtered or unexported fields
}

框架实例

func New

func New() *App

返回一个基本配置的框架实例

func (*App) ServeHTTP

func (app *App) ServeHTTP(resp http.ResponseWriter, req *http.Request)

实现http.Handler接口

type AppConfig added in v0.7.0

type AppConfig struct {
	// Recovery              bool         // 启用自动恢复
	RedirectTrailingSlash bool         // 自动重定向到结尾带有或不带有斜杠的URL
	FixPath               bool         // 清理URL中的不规范路径分隔符,例如//和../
	HandleOPTIONS         bool         // 自定响应OPTIONS请求
	EventHandler          EventHandler // 事件处理器,如果未传值则认为不记录事件
	EventTrigger          bool         // 记录事件的触发信息(影响性能)
	EventTrace            bool         // 启用事件的跟踪信息(影响性能)
	EventShortPath        bool         // 使用事件触发信息的短文件名
}

框架配置

type Context

type Context struct {
	Request *http.Request
	// responseWriter customResponseWriter  // 自定义response
	// ResponseWriter _CustomResponseWriter // 用自定义resp替代http.resp
	ResponseWriter http.ResponseWriter
	// contains filtered or unexported fields
}

连接上下文

func (*Context) GetValue added in v0.7.0

func (ctx *Context) GetValue(key string) interface{}

获取ctx里的值,取出后根据写入的类型自行断言

func (*Context) Next

func (ctx *Context) Next()

继续执行下一个中间件或处理器

func (*Context) Param added in v0.7.0

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

获取路由参数值

func (*Context) ParamValue added in v0.7.0

func (ctx *Context) ParamValue(key string) string

获取某个路由参数值的string类型

func (*Context) Post added in v0.7.0

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

获取某个POST参数值

func (*Context) PostValue added in v0.7.0

func (ctx *Context) PostValue(key string) string

获取某个POST参数值的string类型

func (*Context) Posts added in v0.7.0

func (ctx *Context) Posts() url.Values

获取所有POST参数值

func (*Context) Query added in v0.7.0

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

获取某个GET参数值

func (*Context) QueryValue

func (ctx *Context) QueryValue(key string) string

获取某个GET参数值的string类型

func (*Context) Querys added in v0.7.0

func (ctx *Context) Querys() url.Values

获取所有GET参数值

func (*Context) Redirect

func (ctx *Context) Redirect(code int, url string) error

向客户端发送重定向响应

func (*Context) RemoteIP added in v0.7.0

func (ctx *Context) RemoteIP() string

透过nginx反向代理获得客户端真实IP

func (*Context) RouteValues added in v0.4.1

func (ctx *Context) RouteValues() []httprouter.Param

获取所有路由参数值

func (*Context) SetValue added in v0.7.0

func (ctx *Context) SetValue(key string, value interface{})

在ctx里存储值,如果key存在则替换值

type Event

type Event struct {
	Status         int      // HTTP状态码
	Message        error    // 消息文本
	Trigger        _Trigger // 触发信息
	Trace          []string // 跟踪信息
	ResponseWriter http.ResponseWriter
	Request        *http.Request
}

事件结构

type EventHandler

type EventHandler func(*Event)

事件处理器类型

type Handler

type Handler func(*Context) error

路由处理器

type RouterGroup

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

路由组

func (*RouterGroup) DELETE

func (r *RouterGroup) DELETE(path string, handler Handler, middlewareHandlers ...Handler)

DELETE 路由

func (*RouterGroup) FILE

func (r *RouterGroup) FILE(url string, local string)

FILE 定义路由到文件,不支持路由组和中间件

func (*RouterGroup) GET

func (r *RouterGroup) GET(path string, handler Handler, middlewareHandlers ...Handler)

GET 路由

func (*RouterGroup) GROUP

func (r *RouterGroup) GROUP(path string, handlers ...Handler) *RouterGroup

GROUP 路由组

func (*RouterGroup) HEAD

func (r *RouterGroup) HEAD(path string, handler Handler, middlewareHandlers ...Handler)

HEAD 路由

func (*RouterGroup) Handle

func (r *RouterGroup) Handle(method string, path string, handler Handler, middlewareHandlers ...Handler)

Handle 路由

func (*RouterGroup) OPTIONS

func (r *RouterGroup) OPTIONS(path string, handler Handler, middlewareHandlers ...Handler)

OPTIONS 路由

func (*RouterGroup) PATCH

func (r *RouterGroup) PATCH(path string, handler Handler, middlewareHandlers ...Handler)

PATCH 路由

func (*RouterGroup) PATH

func (r *RouterGroup) PATH(url string, local string, list bool)

PATH 定义路由到目录,不支持路由组和中间件

func (*RouterGroup) POST

func (r *RouterGroup) POST(path string, handler Handler, middlewareHandlers ...Handler)

POST 路由

func (*RouterGroup) PUT

func (r *RouterGroup) PUT(path string, handler Handler, middlewareHandlers ...Handler)

PUT 路由

Jump to

Keyboard shortcuts

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