github.com/gogf/gf@v1.16.9/.example/net/ghttp/server/hooks/hooks1.go (about) 1 package main 2 3 import ( 4 "github.com/gogf/gf/frame/g" 5 "github.com/gogf/gf/net/ghttp" 6 "github.com/gogf/gf/os/glog" 7 ) 8 9 func main() { 10 // 基本事件回调使用 11 p := "/:name/info/{uid}" 12 s := g.Server() 13 s.BindHookHandlerByMap(p, map[string]ghttp.HandlerFunc{ 14 ghttp.HookBeforeServe: func(r *ghttp.Request) { glog.Println(ghttp.HookBeforeServe) }, 15 ghttp.HookAfterServe: func(r *ghttp.Request) { glog.Println(ghttp.HookAfterServe) }, 16 ghttp.HookBeforeOutput: func(r *ghttp.Request) { glog.Println(ghttp.HookBeforeOutput) }, 17 ghttp.HookAfterOutput: func(r *ghttp.Request) { glog.Println(ghttp.HookAfterOutput) }, 18 }) 19 s.BindHandler(p, func(r *ghttp.Request) { 20 r.Response.Write("用户:", r.Get("name"), ", uid:", r.Get("uid")) 21 }) 22 s.SetPort(8199) 23 s.Run() 24 }