Documentation ¶
Index ¶
- func InitSession(cookieName string, cache *cache.Manager)
- type Context
- func (o *Context) DecodeRequestBodyAsJSON(v interface{}) error
- func (o *Context) GetSeesion() cache.Entity
- func (o *Context) NamedParamInURL(name string) string
- func (o *Context) ParamInForm(name string) string
- func (o *Context) ParamInURL(name string) string
- func (o *Context) ResponseHeaderAdd(key, value string)
- func (o *Context) ResponseHeaderSet(key, value string)
- func (o *Context) ResponseJSON(jsonObject interface{})
- func (o *Context) ResponseJSONStatus(status int, jsonObject interface{})
- func (o *Context) ResponseJSONSuccess()
- func (o *Context) ResponseText(text string)
- func (o *Context) ResponseTextStatus(status int, text string)
- func (o *Context) ResponseTextSuccess()
- func (o *Context) ResponseTextf(status int, formatter string, a ...interface{})
- func (o *Context) ReturnFile(filePath string)
- type Handler
- type Intercptor
- type JumpoutError
- type Manager
- type PanicHandler
- type Router
- func (rc *Router) AddAfterInterceptor(interceptor Intercptor)
- func (rc *Router) AddBeforeInterceptor(interceptor Intercptor)
- func (rc *Router) AddPanicHandler(handler PanicHandler)
- func (rc *Router) DELETE(path string, handler Handler)
- func (rc *Router) GET(path string, handler Handler)
- func (rc *Router) GetHTTPRouter() *httprouter.Router
- func (rc *Router) HEAD(path string, handler Handler)
- func (rc *Router) POST(path string, handler Handler)
- func (rc *Router) PUT(path string, handler Handler)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func InitSession ¶
InitSession 初始化 要使用 Session 功能必须在程序初始化时调用此函数
Types ¶
type Context ¶
type Context struct { Writer http.ResponseWriter Request *http.Request // contains filtered or unexported fields }
Context http 请求信息定义
func (*Context) DecodeRequestBodyAsJSON ¶
DecodeRequestBodyAsJSON 把请求内容解析为 json
func (*Context) GetSeesion ¶
GetSeesion 获取 session 使用 session 的话,需要在 main 包中初始化 例:
cache := cache.NewCacheManager(memcache.PROVIDER, 600) session.InitSeesion("go-session", cache)
func (*Context) NamedParamInURL ¶
NamedParamInURL 获取 url 中命名的参数,参见 httprouter 的参数名称 例如: /getinfo/:user
获取 :user 位置的参数,可使用此函数 NamedParamInURL('user')
func (*Context) ParamInForm ¶
ParamInForm 获取 form 中提交的参数
func (*Context) ParamInURL ¶
ParamInURL 获取 url 中名称为 name 的第一个参数的值 注意是 ? 之后的 name=value 形式的参数
func (*Context) ResponseHeaderAdd ¶
ResponseHeaderAdd 追加返回头
func (*Context) ResponseHeaderSet ¶
ResponseHeaderSet 设置返回头
func (*Context) ResponseJSON ¶
func (o *Context) ResponseJSON(jsonObject interface{})
ResponseJSON 返回 json 数据
func (*Context) ResponseJSONStatus ¶
ResponseJSONStatus 返回 JSON 对象 注意:如果该函数执行成功,则会跳过排在该函数后面的代码
func (*Context) ResponseJSONSuccess ¶
func (o *Context) ResponseJSONSuccess()
ResponseJSONSuccess 返回成功,内容为空
func (*Context) ResponseTextStatus ¶
ResponseTextStatus 返回数据并指定状态
func (*Context) ResponseTextSuccess ¶
func (o *Context) ResponseTextSuccess()
ResponseTextSuccess 返回成功,内容为空
func (*Context) ResponseTextf ¶
ResponseTextf 返回 string
func (*Context) ReturnFile ¶
ReturnFile 返回文件,执行该函数不会跳过后面的代码
type Intercptor ¶
Intercptor 拦截器定义 如果要不执行后续操作,直接调用 ctx.Return* 函数
type JumpoutError ¶
type JumpoutError struct {
// contains filtered or unexported fields
}
JumpoutError 跳过后续代码用到的错误定义
func (*JumpoutError) Error ¶
func (e *JumpoutError) Error() string
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager 会话对象
var SSManager *Manager
SSManager 全局变量
func (*Manager) SessionDestory ¶
func (ss *Manager) SessionDestory(w http.ResponseWriter, r *http.Request)
SessionDestory 注销Session
func (*Manager) SessionStart ¶
SessionStart 启动Session功能
type Router ¶
type Router struct { Debug func(messsage string) Error func(err error) // contains filtered or unexported fields }
Router 路由定义 对 httprouter.Router 包装
func (*Router) AddAfterInterceptor ¶
func (rc *Router) AddAfterInterceptor(interceptor Intercptor)
AddAfterInterceptor 添加执行后拦截器, 请勿在 AfterInterceptor 函数中调用 ctx.ResponseHeaderSet 和 ctx.ResponseHeaderAdd 函数
func (*Router) AddBeforeInterceptor ¶
func (rc *Router) AddBeforeInterceptor(interceptor Intercptor)
AddBeforeInterceptor 添加执行前拦截器
func (*Router) AddPanicHandler ¶
func (rc *Router) AddPanicHandler(handler PanicHandler)
AddPanicHandler 添加错误处理函数
func (*Router) GetHTTPRouter ¶
func (rc *Router) GetHTTPRouter() *httprouter.Router
GetHTTPRouter 获取 http handler