github.com/gogf/gf@v1.16.9/.example/net/ghttp/server/hooks/cors2.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 Order(r *ghttp.Request) { 9 r.Response.Write("GET") 10 } 11 12 func main() { 13 s := g.Server() 14 s.Group("/api.v1", func(group *ghttp.RouterGroup) { 15 group.Hook("/*any", ghttp.HookBeforeServe, func(r *ghttp.Request) { 16 r.Response.CORSDefault() 17 }) 18 g.GET("/order", Order) 19 }) 20 s.SetPort(8199) 21 s.Run() 22 }