mirror of
https://gitee.com/johng/gf
synced 2026-07-04 21:03:13 +08:00
改进ghttp事件回调名称
This commit is contained in:
@ -12,14 +12,14 @@ func (s *Server) startCloseQueueLoop() {
|
||||
for {
|
||||
if v := s.closeQueue.PopFront(); v != nil {
|
||||
r := v.(*Request)
|
||||
s.callHookHandler(r, "BeforeRequestClose")
|
||||
s.callHookHandler(r, "BeforeClose")
|
||||
|
||||
// 关闭当前会话的Cookie
|
||||
r.Cookie.Close()
|
||||
// 更新Session会话超时时间
|
||||
r.Session.UpdateExpire()
|
||||
|
||||
s.callHookHandler(r, "AfterRequestClose")
|
||||
s.callHookHandler(r, "AfterClose")
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
@ -78,22 +78,21 @@ func (s *Server)callHandler(h *HandlerItem, r *Request) {
|
||||
s.callHookHandler(r, "AfterServe")
|
||||
|
||||
// 路由规则打包
|
||||
s.callHookHandler(r, "BeforeRouterPatch")
|
||||
s.callHookHandler(r, "BeforePatch")
|
||||
if buffer, err := s.Router.Patch(r.Response.Buffer()); err == nil {
|
||||
r.Response.ClearBuffer()
|
||||
r.Response.Write(buffer)
|
||||
}
|
||||
s.callHookHandler(r, "AfterRouterPatch")
|
||||
s.callHookHandler(r, "AfterPatch")
|
||||
|
||||
s.callHookHandler(r, "BeforeOutput")
|
||||
|
||||
// 输出Cookie
|
||||
s.callHookHandler(r, "BeforeCookieOutput")
|
||||
r.Cookie.Output()
|
||||
s.callHookHandler(r, "AfterCookieOutput")
|
||||
|
||||
// 输出缓冲区
|
||||
s.callHookHandler(r, "BeforeBufferOutput")
|
||||
r.Response.OutputBuffer()
|
||||
s.callHookHandler(r, "AfterBufferOutput")
|
||||
|
||||
s.callHookHandler(r, "AfterOutput")
|
||||
|
||||
// 将Request对象指针丢到队列中异步处理
|
||||
s.closeQueue.PushBack(r)
|
||||
|
||||
@ -8,16 +8,14 @@ import (
|
||||
func main() {
|
||||
pattern := "/"
|
||||
ghttp.GetServer().BindHookHandlerByMap(pattern, map[string]ghttp.HandlerFunc{
|
||||
"BeforeServe" : func(r *ghttp.Request){ fmt.Println("BeforeServe") },
|
||||
"AfterServe" : func(r *ghttp.Request){ fmt.Println("AfterServe") },
|
||||
"BeforeRouterPatch" : func(r *ghttp.Request){ fmt.Println("BeforeRouterPatch") },
|
||||
"AfterRouterPatch" : func(r *ghttp.Request){ fmt.Println("AfterRouterPatch") },
|
||||
"BeforeCookieOutput" : func(r *ghttp.Request){ fmt.Println("BeforeCookieOutput") },
|
||||
"AfterCookieOutput" : func(r *ghttp.Request){ fmt.Println("AfterCookieOutput") },
|
||||
"BeforeBufferOutput" : func(r *ghttp.Request){ fmt.Println("BeforeBufferOutput") },
|
||||
"AfterBufferOutput" : func(r *ghttp.Request){ fmt.Println("AfterBufferOutput") },
|
||||
"BeforeRequestClose" : func(r *ghttp.Request){ fmt.Println("BeforeRequestClose") },
|
||||
"AfterRequestClose" : func(r *ghttp.Request){ fmt.Println("AfterRequestClose") },
|
||||
"BeforeServe" : func(r *ghttp.Request){ fmt.Println("BeforeServe") },
|
||||
"AfterServe" : func(r *ghttp.Request){ fmt.Println("AfterServe") },
|
||||
"BeforePatch" : func(r *ghttp.Request){ fmt.Println("BeforePatch") },
|
||||
"AfterPatch" : func(r *ghttp.Request){ fmt.Println("AfterPatch") },
|
||||
"BeforeOutput" : func(r *ghttp.Request){ fmt.Println("BeforeOutput") },
|
||||
"AfterOutput" : func(r *ghttp.Request){ fmt.Println("AfterOutput") },
|
||||
"BeforeClose" : func(r *ghttp.Request){ fmt.Println("BeforeClose") },
|
||||
"AfterClose" : func(r *ghttp.Request){ fmt.Println("AfterClose") },
|
||||
})
|
||||
ghttp.GetServer().BindHandler(pattern, func(r *ghttp.Request) {
|
||||
r.Response.WriteString("Hello World!")
|
||||
|
||||
Reference in New Issue
Block a user