github.com/gogf/gf@v1.16.9/.example/net/ghttp/server/exit.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  	p := "/"
    11  	s := g.Server()
    12  	s.BindHandler(p, func(r *ghttp.Request) {
    13  		r.Response.Writeln("start")
    14  		r.Exit()
    15  		r.Response.Writeln("end")
    16  	})
    17  	s.BindHookHandlerByMap(p, map[string]ghttp.HandlerFunc{
    18  		ghttp.HookBeforeServe: func(r *ghttp.Request) {
    19  			glog.To(r.Response.Writer).Println("BeforeServe")
    20  		},
    21  		ghttp.HookAfterServe: func(r *ghttp.Request) {
    22  			glog.To(r.Response.Writer).Println("AfterServe")
    23  		},
    24  	})
    25  	s.SetPort(8199)
    26  	s.Run()
    27  }