tsing

package module
v0.4.2 Latest Latest
Warning

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

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

README

Tsing

由dxvgef/httpdispatcher项目更名而来

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type App

type App struct {
	// 事件配置
	Event struct {
		Handler     EventHandler // 事件处理器,如果未传值则认为不记录事件
		EnableTrace bool         // 启用500事件的跟踪(影响性能)
		ShortCaller bool         // 缩短事件触发的源码文件名(仅记录源码文件名,仅对ctx.Return触发的500事件有效)s
	}
	// 路由器
	Router RouterGroup
	// contains filtered or unexported fields
}

App 框架实例

func New

func New() *App

New 返回一个框架实例

func (*App) ServeHTTP

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

type Context

type Context struct {
	Request        *http.Request
	ResponseWriter http.ResponseWriter

	Next bool // 继续执行下一个中间件或处理器
	// contains filtered or unexported fields
}

Context 上下文

func (Context) Break added in v0.4.0

func (ctx Context) Break(err error) (Context, error)

Break 中断,不继续执行下一个中间件或处理器,如果err不为nil,则同时抛出500事件

func (Context) ContextValue

func (ctx Context) ContextValue(key string) interface{}

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

func (Context) Continue added in v0.4.0

func (ctx Context) Continue() (Context, error)

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

func (Context) Event

func (ctx Context) Event(err error) error

Event 触发500事件,使用此方法是为了精准记录触发事件的源码文件及行号

func (Context) FormValue

func (ctx Context) FormValue(key string) ReqValue

FormValue 获取某个POST参数值

func (Context) FormValues added in v0.4.1

func (ctx Context) FormValues() url.Values

FormValues 获取所有GET/POST参数值

func (Context) PostValues added in v0.4.1

func (ctx Context) PostValues() url.Values

PostValues 获取所有POST参数值

func (Context) QueryValue

func (ctx Context) QueryValue(key string) ReqValue

QueryValue 获取某个GET参数值

func (Context) QueryValues added in v0.4.1

func (ctx Context) QueryValues() url.Values

QueryValues 获取所有GET参数值

func (Context) RawFormValue added in v0.4.1

func (ctx Context) RawFormValue(key string) string

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

func (Context) RawQueryValue added in v0.4.1

func (ctx Context) RawQueryValue(key string) string

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

func (Context) RawRouteValue added in v0.4.1

func (ctx Context) RawRouteValue(key string) string

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

func (Context) RealIP

func (ctx Context) RealIP() string

RealIP 获得客户端真实IP

func (Context) Redirect

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

Redirect 重定向

func (Context) RouteValue

func (ctx Context) RouteValue(key string) ReqValue

RouteValue 获取路由参数值

func (Context) RouteValues added in v0.4.1

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

RouteValues 获取所有路由参数值

func (*Context) SetContextValue

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

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

type Event

type Event struct {
	Status         int      // HTTP状态码
	Trace          []string // 触发事件的trace
	Message        error    // 事件消息文本
	ResponseWriter http.ResponseWriter
	Request        *http.Request
}

Event 事件结构

type EventHandler

type EventHandler func(Event)

EventHandler 事件处理器类型

type Handler

type Handler func(Context) error

Handler 处理器类型

type MiddlewareHandler added in v0.4.0

type MiddlewareHandler func(Context) (Context, error)

MiddlewareHandler 中间件处理器

type ReqValue

type ReqValue struct {
	Key   string // 参数名
	Value string // 参数值
	Error error  // 错误
}

ReqValue 请求参数值

func (ReqValue) Bool

func (bv ReqValue) Bool(rules ...filter.Rule) (bool, error)

Bool 将参数值转为bool类型

func (ReqValue) Float32

func (bv ReqValue) Float32(rules ...filter.Rule) (float32, error)

Float32 将参数值转为float32类型

func (ReqValue) Float64

func (bv ReqValue) Float64(rules ...filter.Rule) (float64, error)

Float64 将参数值转为float64类型

func (ReqValue) Int

func (bv ReqValue) Int(rules ...filter.Rule) (int, error)

Int 将参数值转为int类型

func (ReqValue) Int32

func (bv ReqValue) Int32(rules ...filter.Rule) (int32, error)

Int32 将参数值转为int32类型

func (ReqValue) Int64

func (bv ReqValue) Int64(rules ...filter.Rule) (int64, error)

Int64 将参数值转为int64类型

func (ReqValue) MustBool

func (bv ReqValue) MustBool(def bool, rules ...filter.Rule) bool

MustBool 将参数值转为bool类型,如果出错或者校验失败则返回默认值

func (ReqValue) MustFloat32

func (bv ReqValue) MustFloat32(def float32, rules ...filter.Rule) float32

MustFloat32 将参数值转为float32类型,如果出错或者校验失败则返回默认值

func (ReqValue) MustFloat64

func (bv ReqValue) MustFloat64(def float64, rules ...filter.Rule) float64

MustFloat64 将参数值转为float64类型,如果出错或者校验失败则返回默认值

func (ReqValue) MustInt

func (bv ReqValue) MustInt(def int, rules ...filter.Rule) int

MustInt 将参数值转为int类型,如果出错或者校验失败则返回默认值

func (ReqValue) MustInt32

func (bv ReqValue) MustInt32(def int32, rules ...filter.Rule) int32

Int32 将参数值转为int32类型,如果出错或者校验失败则返回默认值

func (ReqValue) MustInt64

func (bv ReqValue) MustInt64(def int64, rules ...filter.Rule) int64

MustInt64 将参数值转为int64类型,如果出错或者校验失败则返回默认值

func (ReqValue) MustString

func (bv ReqValue) MustString(def string, rules ...filter.Rule) string

MustString将参数值转为string,如果出错或者校验失败则返回默认值

func (ReqValue) MustUint32

func (bv ReqValue) MustUint32(def uint32, rules ...filter.Rule) uint32

MustUint32 将参数值转为uint32类型,如果出错或者校验失败则返回默认值

func (ReqValue) MustUint64

func (bv ReqValue) MustUint64(def uint64, rules ...filter.Rule) uint64

MustUint64 将参数值转为uint64类型,如果出错或者校验失败则返回默认值

func (ReqValue) String

func (bv ReqValue) String(rules ...filter.Rule) (string, error)

String将参数值转为string

func (ReqValue) Uint32

func (bv ReqValue) Uint32(rules ...filter.Rule) (uint32, error)

Uint32 将参数值转为uint32类型

func (ReqValue) Uint64

func (bv ReqValue) Uint64(rules ...filter.Rule) (uint64, error)

Uint64 将参数值转为uint64类型

type RouterGroup

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

RouterGroup 路由组

func (*RouterGroup) DELETE

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

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 ...MiddlewareHandler)

GET 路由

func (*RouterGroup) GROUP

func (r *RouterGroup) GROUP(path string, middlewareHandlers ...MiddlewareHandler) RouterGroup

GROUP 路由组

func (*RouterGroup) HEAD

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

HEAD 路由

func (*RouterGroup) Handle

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

Handle 路由

func (*RouterGroup) OPTIONS

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

OPTIONS 路由

func (*RouterGroup) PATCH

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

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 ...MiddlewareHandler)

POST 路由

func (*RouterGroup) PUT

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

PUT 路由

Jump to

Keyboard shortcuts

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