github.com/gogf/gf@v1.16.9/.example/net/ghttp/server/router/router4.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  	// 该路由规则仅会在GET请求下有效
    11  	s.BindHandler("GET:/{table}/list/{page}.html", func(r *ghttp.Request) {
    12  		r.Response.WriteJson(r.Router)
    13  	})
    14  	// 该路由规则仅会在GET请求及localhost域名下有效
    15  	s.BindHandler("GET:/order/info/{order_id}@localhost", func(r *ghttp.Request) {
    16  		r.Response.WriteJson(r.Router)
    17  	})
    18  	// 该路由规则仅会在DELETE请求下有效
    19  	s.BindHandler("DELETE:/comment/{id}", func(r *ghttp.Request) {
    20  		r.Response.WriteJson(r.Router)
    21  	})
    22  	s.SetPort(8199)
    23  	s.Run()
    24  }