Files
gf/.example/net/ghttp/server/exit.go

28 lines
609 B
Go
Raw Normal View History

package main
import (
2021-10-11 21:41:56 +08:00
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/net/ghttp"
"github.com/gogf/gf/v2/os/glog"
)
func main() {
2019-04-03 00:03:46 +08:00
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{
2020-12-14 13:26:48 +08:00
ghttp.HookBeforeServe: func(r *ghttp.Request) {
2021-11-01 19:46:39 +08:00
glog.To(r.Response.Writer).Print(r.Context(), "BeforeServe")
2019-04-03 00:03:46 +08:00
},
2020-12-14 13:26:48 +08:00
ghttp.HookAfterServe: func(r *ghttp.Request) {
2021-11-01 19:46:39 +08:00
glog.To(r.Response.Writer).Print(r.Context(), "AfterServe")
2019-04-03 00:03:46 +08:00
},
})
s.SetPort(8199)
s.Run()
}