github.com/gogf/gf@v1.16.9/.example/net/ghttp/server/hooks/same_route_multi_hook.go (about)

     1  package main
     2  
     3  import (
     4  	"github.com/gogf/gf/frame/g"
     5  	"github.com/gogf/gf/net/ghttp"
     6  )
     7  
     8  func main() {
     9  	s := g.Server()
    10  	s.BindHandler("/priority/show", func(r *ghttp.Request) {
    11  		r.Response.Writeln("priority service")
    12  	})
    13  
    14  	s.BindHookHandlerByMap("/priority/:name", map[string]ghttp.HandlerFunc{
    15  		ghttp.HookBeforeServe: func(r *ghttp.Request) {
    16  			r.Response.Writeln("/priority/:name")
    17  		},
    18  	})
    19  	s.BindHookHandlerByMap("/priority/*any", map[string]ghttp.HandlerFunc{
    20  		ghttp.HookBeforeServe: func(r *ghttp.Request) {
    21  			r.Response.Writeln("/priority/*any")
    22  		},
    23  	})
    24  	s.BindHookHandlerByMap("/priority/show", map[string]ghttp.HandlerFunc{
    25  		ghttp.HookBeforeServe: func(r *ghttp.Request) {
    26  			r.Response.Writeln("/priority/show")
    27  		},
    28  	})
    29  	s.SetPort(8199)
    30  	s.Run()
    31  }