package main import ( "github.com/gogf/gf/v2/frame/g" "github.com/gogf/gf/v2/net/ghttp" "github.com/gogf/gf/v2/os/glog" ) func main() { p := "/" s := g.Server() s.BindHandler(p, func(r *ghttp.Request) { r.Response.Writeln("start") r.Exit() r.Response.Writeln("end") }) s.BindHookHandlerByMap(p, map[string]ghttp.HandlerFunc{ ghttp.HookBeforeServe: func(r *ghttp.Request) { glog.To(r.Response.Writer).Print(r.Context(), "BeforeServe") }, ghttp.HookAfterServe: func(r *ghttp.Request) { glog.To(r.Response.Writer).Print(r.Context(), "AfterServe") }, }) s.SetPort(8199) s.Run() }