main2.go 784 B

123456789101112131415161718192021222324
  1. package main
  2. import (
  3. "github.com/gogf/gf/frame/g"
  4. "github.com/gogf/gf/net/ghttp"
  5. "github.com/gogf/gf/os/glog"
  6. )
  7. func main() {
  8. // 基本事件回调使用
  9. p := "/:name/info/{uid}"
  10. s := g.Server()
  11. s.BindHookHandlerByMap(p, map[string]ghttp.HandlerFunc{
  12. ghttp.HOOK_BEFORE_SERVE : func(r *ghttp.Request){ glog.Println(ghttp.HOOK_BEFORE_SERVE) },
  13. ghttp.HOOK_AFTER_SERVE : func(r *ghttp.Request){ glog.Println(ghttp.HOOK_AFTER_SERVE) },
  14. ghttp.HOOK_BEFORE_OUTPUT : func(r *ghttp.Request){ glog.Println(ghttp.HOOK_BEFORE_OUTPUT) },
  15. ghttp.HOOK_AFTER_OUTPUT : func(r *ghttp.Request){ glog.Println(ghttp.HOOK_AFTER_OUTPUT) },
  16. })
  17. s.BindHandler(p, func(r *ghttp.Request) {
  18. r.Response.Write("用户:", r.Get("name"), ", uid:", r.Get("uid"))
  19. })
  20. s.SetPort(8199)
  21. s.Run()
  22. }