demo2_test.go 876 B

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