mirror of
https://gitee.com/johng/gf
synced 2026-06-06 16:21:40 +08:00
change routergroup parameter name 'g' to 'group' for unit testing cases of ghttp
This commit is contained in:
@ -70,10 +70,10 @@ func UploadShowBatch(r *ghttp.Request) {
|
||||
|
||||
func main() {
|
||||
s := g.Server()
|
||||
s.Group("/upload", func(g *ghttp.RouterGroup) {
|
||||
g.ALL("/", Upload)
|
||||
g.ALL("/show", UploadShow)
|
||||
g.ALL("/batch", UploadShowBatch)
|
||||
s.Group("/upload", func(group *ghttp.RouterGroup) {
|
||||
group.ALL("/", Upload)
|
||||
group.ALL("/show", UploadShow)
|
||||
group.ALL("/batch", UploadShowBatch)
|
||||
})
|
||||
s.SetPort(8199)
|
||||
s.Run()
|
||||
|
||||
@ -70,10 +70,10 @@ func UploadShowBatch(r *ghttp.Request) {
|
||||
|
||||
func main() {
|
||||
s := g.Server()
|
||||
s.Group("/upload", func(g *ghttp.RouterGroup) {
|
||||
g.ALL("/", Upload)
|
||||
g.ALL("/show", UploadShow)
|
||||
g.ALL("/batch", UploadShowBatch)
|
||||
s.Group("/upload", func(group *ghttp.RouterGroup) {
|
||||
group.ALL("/", Upload)
|
||||
group.ALL("/show", UploadShow)
|
||||
group.ALL("/batch", UploadShowBatch)
|
||||
})
|
||||
s.SetPort(8199)
|
||||
s.Run()
|
||||
|
||||
@ -16,8 +16,8 @@ func Order(r *ghttp.Request) {
|
||||
|
||||
func main() {
|
||||
s := g.Server()
|
||||
s.Group("/api.v1", func(g *ghttp.RouterGroup) {
|
||||
g.Middleware(MiddlewareCORS)
|
||||
s.Group("/api.v1", func(group *ghttp.RouterGroup) {
|
||||
group.Middleware(MiddlewareCORS)
|
||||
g.GET("/order", Order)
|
||||
})
|
||||
s.SetPort(8199)
|
||||
|
||||
@ -18,8 +18,8 @@ func Order(r *ghttp.Request) {
|
||||
|
||||
func main() {
|
||||
s := g.Server()
|
||||
s.Group("/api.v1", func(g *ghttp.RouterGroup) {
|
||||
g.Middleware(MiddlewareCORS)
|
||||
s.Group("/api.v1", func(group *ghttp.RouterGroup) {
|
||||
group.Middleware(MiddlewareCORS)
|
||||
g.GET("/order", Order)
|
||||
})
|
||||
s.SetPort(8199)
|
||||
|
||||
@ -24,8 +24,8 @@ func Order(r *ghttp.Request) {
|
||||
|
||||
func main() {
|
||||
s := g.Server()
|
||||
s.Group("/api.v1", func(g *ghttp.RouterGroup) {
|
||||
g.Middleware(MiddlewareCORS)
|
||||
s.Group("/api.v1", func(group *ghttp.RouterGroup) {
|
||||
group.Middleware(MiddlewareCORS)
|
||||
g.GET("/order", Order)
|
||||
})
|
||||
s.SetPort(8199)
|
||||
|
||||
@ -11,7 +11,7 @@ func Order(r *ghttp.Request) {
|
||||
|
||||
func main() {
|
||||
s := g.Server()
|
||||
s.Group("/api.v1", func(g *ghttp.RouterGroup) {
|
||||
s.Group("/api.v1", func(group *ghttp.RouterGroup) {
|
||||
g.GET("/order", Order)
|
||||
})
|
||||
s.SetPort(8199)
|
||||
|
||||
@ -11,8 +11,8 @@ func Order(r *ghttp.Request) {
|
||||
|
||||
func main() {
|
||||
s := g.Server()
|
||||
s.Group("/api.v1", func(g *ghttp.RouterGroup) {
|
||||
g.Hook("/*any", ghttp.HOOK_BEFORE_SERVE, func(r *ghttp.Request) {
|
||||
s.Group("/api.v1", func(group *ghttp.RouterGroup) {
|
||||
group.Hook("/*any", ghttp.HOOK_BEFORE_SERVE, func(r *ghttp.Request) {
|
||||
r.Response.CORSDefault()
|
||||
})
|
||||
g.GET("/order", Order)
|
||||
|
||||
@ -8,11 +8,11 @@ import (
|
||||
|
||||
func main() {
|
||||
s := g.Server()
|
||||
s.Group("/", func(g *ghttp.RouterGroup) {
|
||||
g.ALL("/", func(r *ghttp.Request) {
|
||||
s.Group("/", func(group *ghttp.RouterGroup) {
|
||||
group.ALL("/", func(r *ghttp.Request) {
|
||||
r.Response.Write("halo world!")
|
||||
})
|
||||
g.ALL("/log/handler", func(r *ghttp.Request) {
|
||||
group.ALL("/log/handler", func(r *ghttp.Request) {
|
||||
r.Response.WriteStatus(http.StatusNotFound, "File Not Found!")
|
||||
})
|
||||
})
|
||||
|
||||
@ -23,9 +23,9 @@ func MiddlewareCORS(r *ghttp.Request) {
|
||||
|
||||
func main() {
|
||||
s := g.Server()
|
||||
s.Group("/api.v2", func(g *ghttp.RouterGroup) {
|
||||
g.Middleware(MiddlewareAuth, MiddlewareCORS)
|
||||
g.ALL("/user/list", func(r *ghttp.Request) {
|
||||
s.Group("/api.v2", func(group *ghttp.RouterGroup) {
|
||||
group.Middleware(MiddlewareAuth, MiddlewareCORS)
|
||||
group.ALL("/user/list", func(r *ghttp.Request) {
|
||||
r.Response.Write("list")
|
||||
})
|
||||
})
|
||||
|
||||
@ -18,7 +18,7 @@ func MiddlewareAuth(r *ghttp.Request) {
|
||||
|
||||
func main() {
|
||||
s := g.Server()
|
||||
s.Group("/admin", func(g *ghttp.RouterGroup) {
|
||||
s.Group("/admin", func(group *ghttp.RouterGroup) {
|
||||
g.MiddlewarePattern("/*action", func(r *ghttp.Request) {
|
||||
if action := r.GetRouterString("action"); action != "" {
|
||||
switch action {
|
||||
@ -29,10 +29,10 @@ func main() {
|
||||
}
|
||||
MiddlewareAuth(r)
|
||||
})
|
||||
g.ALL("/login", func(r *ghttp.Request) {
|
||||
group.ALL("/login", func(r *ghttp.Request) {
|
||||
r.Response.Write("login")
|
||||
})
|
||||
g.ALL("/dashboard", func(r *ghttp.Request) {
|
||||
group.ALL("/dashboard", func(r *ghttp.Request) {
|
||||
r.Response.Write("dashboard")
|
||||
})
|
||||
})
|
||||
|
||||
@ -12,9 +12,9 @@ func MiddlewareCORS(r *ghttp.Request) {
|
||||
|
||||
func main() {
|
||||
s := g.Server()
|
||||
s.Group("/api.v2", func(g *ghttp.RouterGroup) {
|
||||
g.Middleware(MiddlewareCORS)
|
||||
g.ALL("/user/list", func(r *ghttp.Request) {
|
||||
s.Group("/api.v2", func(group *ghttp.RouterGroup) {
|
||||
group.Middleware(MiddlewareCORS)
|
||||
group.ALL("/user/list", func(r *ghttp.Request) {
|
||||
r.Response.Write("list")
|
||||
})
|
||||
})
|
||||
|
||||
@ -31,9 +31,9 @@ func MiddlewareError(r *ghttp.Request) {
|
||||
|
||||
func main() {
|
||||
s := g.Server()
|
||||
s.Group("/api.v2", func(g *ghttp.RouterGroup) {
|
||||
g.Middleware(MiddlewareAuth, MiddlewareCORS, MiddlewareError)
|
||||
g.ALL("/user/list", func(r *ghttp.Request) {
|
||||
s.Group("/api.v2", func(group *ghttp.RouterGroup) {
|
||||
group.Middleware(MiddlewareAuth, MiddlewareCORS, MiddlewareError)
|
||||
group.ALL("/user/list", func(r *ghttp.Request) {
|
||||
panic("db error: sql is xxxxxxx")
|
||||
})
|
||||
})
|
||||
|
||||
@ -30,12 +30,12 @@ func MiddlewareLog(r *ghttp.Request) {
|
||||
|
||||
func main() {
|
||||
s := g.Server()
|
||||
s.Group("/", func(g *ghttp.RouterGroup) {
|
||||
g.Middleware(MiddlewareLog)
|
||||
s.Group("/", func(group *ghttp.RouterGroup) {
|
||||
group.Middleware(MiddlewareLog)
|
||||
})
|
||||
s.Group("/api.v2", func(g *ghttp.RouterGroup) {
|
||||
g.Middleware(MiddlewareAuth, MiddlewareCORS)
|
||||
g.ALL("/user/list", func(r *ghttp.Request) {
|
||||
s.Group("/api.v2", func(group *ghttp.RouterGroup) {
|
||||
group.Middleware(MiddlewareAuth, MiddlewareCORS)
|
||||
group.ALL("/user/list", func(r *ghttp.Request) {
|
||||
panic("custom error")
|
||||
})
|
||||
})
|
||||
|
||||
@ -7,18 +7,18 @@ import (
|
||||
|
||||
func main() {
|
||||
s := g.Server()
|
||||
s.Group("/api.v2", func(g *ghttp.RouterGroup) {
|
||||
g.Middleware(func(r *ghttp.Request) {
|
||||
s.Group("/api.v2", func(group *ghttp.RouterGroup) {
|
||||
group.Middleware(func(r *ghttp.Request) {
|
||||
r.Response.Write("start")
|
||||
r.Middleware.Next()
|
||||
r.Response.Write("end")
|
||||
})
|
||||
g.Group("/order", func(g *ghttp.RouterGroup) {
|
||||
g.Group("/order", func(group *ghttp.RouterGroup) {
|
||||
g.GET("/list", func(r *ghttp.Request) {
|
||||
r.Response.Write("list")
|
||||
})
|
||||
})
|
||||
g.Group("/user", func(g *ghttp.RouterGroup) {
|
||||
g.Group("/user", func(group *ghttp.RouterGroup) {
|
||||
g.GET("/info", func(r *ghttp.Request) {
|
||||
r.Response.Write("info")
|
||||
})
|
||||
@ -26,11 +26,11 @@ func main() {
|
||||
r.Response.Write("edit")
|
||||
})
|
||||
})
|
||||
g.Group("/hook", func(g *ghttp.RouterGroup) {
|
||||
g.Hook("/*", ghttp.HOOK_BEFORE_SERVE, func(r *ghttp.Request) {
|
||||
g.Group("/hook", func(group *ghttp.RouterGroup) {
|
||||
group.Hook("/*", ghttp.HOOK_BEFORE_SERVE, func(r *ghttp.Request) {
|
||||
r.Response.Write("hook any")
|
||||
})
|
||||
g.Hook("/:name", ghttp.HOOK_BEFORE_SERVE, func(r *ghttp.Request) {
|
||||
group.Hook("/:name", ghttp.HOOK_BEFORE_SERVE, func(r *ghttp.Request) {
|
||||
r.Response.Write("hook name")
|
||||
})
|
||||
})
|
||||
|
||||
@ -15,8 +15,8 @@ type User struct {
|
||||
|
||||
func main() {
|
||||
s := g.Server()
|
||||
s.Group("/", func(rg *ghttp.RouterGroup) {
|
||||
rg.ALL("/user", func(r *ghttp.Request) {
|
||||
s.Group("/", func(rgroup *ghttp.RouterGroup) {
|
||||
rgroup.ALL("/user", func(r *ghttp.Request) {
|
||||
user := new(User)
|
||||
if err := r.GetToStruct(user); err != nil {
|
||||
r.Response.WriteJsonExit(g.Map{
|
||||
|
||||
@ -29,15 +29,15 @@ func MiddlewareLog(r *ghttp.Request) {
|
||||
|
||||
func main() {
|
||||
s := g.Server()
|
||||
s.Group("/", func(g *ghttp.RouterGroup) {
|
||||
g.Middleware(MiddlewareLog)
|
||||
s.Group("/", func(group *ghttp.RouterGroup) {
|
||||
group.Middleware(MiddlewareLog)
|
||||
})
|
||||
s.Group("/api.v2", func(g *ghttp.RouterGroup) {
|
||||
g.Middleware(MiddlewareAuth, MiddlewareCORS)
|
||||
s.Group("/api.v2", func(group *ghttp.RouterGroup) {
|
||||
group.Middleware(MiddlewareAuth, MiddlewareCORS)
|
||||
g.GET("/test", func(r *ghttp.Request) {
|
||||
r.Response.Write("test")
|
||||
})
|
||||
g.Group("/order", func(g *ghttp.RouterGroup) {
|
||||
g.Group("/order", func(group *ghttp.RouterGroup) {
|
||||
g.GET("/list", func(r *ghttp.Request) {
|
||||
r.Response.Write("list")
|
||||
})
|
||||
@ -45,7 +45,7 @@ func main() {
|
||||
r.Response.Write("update")
|
||||
})
|
||||
})
|
||||
g.Group("/user", func(g *ghttp.RouterGroup) {
|
||||
g.Group("/user", func(group *ghttp.RouterGroup) {
|
||||
g.GET("/info", func(r *ghttp.Request) {
|
||||
r.Response.Write("info")
|
||||
})
|
||||
@ -56,11 +56,11 @@ func main() {
|
||||
r.Response.Write("drop")
|
||||
})
|
||||
})
|
||||
g.Group("/hook", func(g *ghttp.RouterGroup) {
|
||||
g.Hook("/*", ghttp.HOOK_BEFORE_SERVE, func(r *ghttp.Request) {
|
||||
g.Group("/hook", func(group *ghttp.RouterGroup) {
|
||||
group.Hook("/*", ghttp.HOOK_BEFORE_SERVE, func(r *ghttp.Request) {
|
||||
r.Response.Write("hook any")
|
||||
})
|
||||
g.Hook("/:name", ghttp.HOOK_BEFORE_SERVE, func(r *ghttp.Request) {
|
||||
group.Hook("/:name", ghttp.HOOK_BEFORE_SERVE, func(r *ghttp.Request) {
|
||||
r.Response.Write("hook name")
|
||||
})
|
||||
})
|
||||
|
||||
@ -8,7 +8,7 @@ import (
|
||||
|
||||
func main() {
|
||||
s := g.Server()
|
||||
s.Group("/", func(g *ghttp.RouterGroup) {
|
||||
s.Group("/", func(group *ghttp.RouterGroup) {
|
||||
g.GET("/set", func(r *ghttp.Request) {
|
||||
r.Session.Set("time", gtime.Second())
|
||||
r.Response.Write("ok")
|
||||
|
||||
@ -1,22 +1,15 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/gogf/gf/net/ghttp"
|
||||
)
|
||||
|
||||
func main() {
|
||||
s := ghttp.GetServer()
|
||||
s.BindHandler("/admin", func(r *ghttp.Request) {
|
||||
r.Response.Write("admin")
|
||||
})
|
||||
s.BindHandler("/admin-{page}", func(r *ghttp.Request) {
|
||||
r.Response.Write("admin-{page}", r.GetInt("page"))
|
||||
})
|
||||
s.BindHandler("/admin-goods", func(r *ghttp.Request) {
|
||||
r.Response.Write("admin-goods")
|
||||
})
|
||||
s.BindHandler("/admin-goods-{page}", func(r *ghttp.Request) {
|
||||
r.Response.Write("admin-goods-{page}", r.GetInt("page"))
|
||||
s.BindHandler("/*", func(r *ghttp.Request) {
|
||||
fmt.Println(r.URL.RawPath)
|
||||
r.Response.Write(r.GetUrl())
|
||||
})
|
||||
s.SetPort(8199)
|
||||
s.Run()
|
||||
|
||||
@ -31,12 +31,12 @@ func (s *Server) EnablePProf(pattern ...string) {
|
||||
up := &utilPProf{}
|
||||
_, _, uri, _ := s.parsePattern(p)
|
||||
uri = strings.TrimRight(uri, "/")
|
||||
s.Group(uri, func(g *RouterGroup) {
|
||||
g.ALL("/*action", up.Index)
|
||||
g.ALL("/cmdline", up.Cmdline)
|
||||
g.ALL("/profile", up.Profile)
|
||||
g.ALL("/symbol", up.Symbol)
|
||||
g.ALL("/trace", up.Trace)
|
||||
s.Group(uri, func(group *RouterGroup) {
|
||||
group.ALL("/*action", up.Index)
|
||||
group.ALL("/cmdline", up.Cmdline)
|
||||
group.ALL("/profile", up.Profile)
|
||||
group.ALL("/symbol", up.Symbol)
|
||||
group.ALL("/trace", up.Trace)
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@ -134,16 +134,16 @@ func Test_BindMiddleware_Basic3(t *testing.T) {
|
||||
func Test_BindMiddleware_Must_Be_Called(t *testing.T) {
|
||||
p := ports.PopRand()
|
||||
s := g.Server(p)
|
||||
s.Group("/", func(g *ghttp.RouterGroup) {
|
||||
g.Middleware(func(r *ghttp.Request) {
|
||||
s.Group("/", func(group *ghttp.RouterGroup) {
|
||||
group.Middleware(func(r *ghttp.Request) {
|
||||
r.Response.Write("1")
|
||||
r.Middleware.Next()
|
||||
})
|
||||
g.Middleware(func(r *ghttp.Request) {
|
||||
group.Middleware(func(r *ghttp.Request) {
|
||||
r.Middleware.Next()
|
||||
r.Response.Write("2")
|
||||
})
|
||||
g.ALL("/test", func(r *ghttp.Request) {
|
||||
group.ALL("/test", func(r *ghttp.Request) {
|
||||
r.Response.Write("test")
|
||||
})
|
||||
})
|
||||
@ -166,13 +166,13 @@ func Test_BindMiddleware_Must_Be_Called(t *testing.T) {
|
||||
func Test_Middleware_With_Static(t *testing.T) {
|
||||
p := ports.PopRand()
|
||||
s := g.Server(p)
|
||||
s.Group("/", func(g *ghttp.RouterGroup) {
|
||||
g.Middleware(func(r *ghttp.Request) {
|
||||
s.Group("/", func(group *ghttp.RouterGroup) {
|
||||
group.Middleware(func(r *ghttp.Request) {
|
||||
r.Response.Write("1")
|
||||
r.Middleware.Next()
|
||||
r.Response.Write("2")
|
||||
})
|
||||
g.ALL("/user/list", func(r *ghttp.Request) {
|
||||
group.ALL("/user/list", func(r *ghttp.Request) {
|
||||
r.Response.Write("list")
|
||||
})
|
||||
})
|
||||
@ -196,12 +196,12 @@ func Test_Middleware_With_Static(t *testing.T) {
|
||||
func Test_Middleware_Status(t *testing.T) {
|
||||
p := ports.PopRand()
|
||||
s := g.Server(p)
|
||||
s.Group("/", func(g *ghttp.RouterGroup) {
|
||||
g.Middleware(func(r *ghttp.Request) {
|
||||
s.Group("/", func(group *ghttp.RouterGroup) {
|
||||
group.Middleware(func(r *ghttp.Request) {
|
||||
r.Middleware.Next()
|
||||
r.Response.WriteOver(r.Response.Status)
|
||||
})
|
||||
g.ALL("/user/list", func(r *ghttp.Request) {
|
||||
group.ALL("/user/list", func(r *ghttp.Request) {
|
||||
r.Response.Write("list")
|
||||
})
|
||||
})
|
||||
@ -228,23 +228,23 @@ func Test_Middleware_Hook_With_Static(t *testing.T) {
|
||||
p := ports.PopRand()
|
||||
s := g.Server(p)
|
||||
a := garray.New(true)
|
||||
s.Group("/", func(g *ghttp.RouterGroup) {
|
||||
g.Hook("/*", ghttp.HOOK_BEFORE_SERVE, func(r *ghttp.Request) {
|
||||
s.Group("/", func(group *ghttp.RouterGroup) {
|
||||
group.Hook("/*", ghttp.HOOK_BEFORE_SERVE, func(r *ghttp.Request) {
|
||||
a.Append(1)
|
||||
fmt.Println("HOOK_BEFORE_SERVE")
|
||||
r.Response.Write("a")
|
||||
})
|
||||
g.Hook("/*", ghttp.HOOK_AFTER_SERVE, func(r *ghttp.Request) {
|
||||
group.Hook("/*", ghttp.HOOK_AFTER_SERVE, func(r *ghttp.Request) {
|
||||
a.Append(1)
|
||||
fmt.Println("HOOK_AFTER_SERVE")
|
||||
r.Response.Write("b")
|
||||
})
|
||||
g.Middleware(func(r *ghttp.Request) {
|
||||
group.Middleware(func(r *ghttp.Request) {
|
||||
r.Response.Write("1")
|
||||
r.Middleware.Next()
|
||||
r.Response.Write("2")
|
||||
})
|
||||
g.ALL("/user/list", func(r *ghttp.Request) {
|
||||
group.ALL("/user/list", func(r *ghttp.Request) {
|
||||
r.Response.Write("list")
|
||||
})
|
||||
})
|
||||
@ -594,9 +594,9 @@ func MiddlewareCORS(r *ghttp.Request) {
|
||||
func Test_Middleware_CORSAndAuth(t *testing.T) {
|
||||
p := ports.PopRand()
|
||||
s := g.Server(p)
|
||||
s.Group("/api.v2", func(g *ghttp.RouterGroup) {
|
||||
g.Middleware(MiddlewareAuth, MiddlewareCORS)
|
||||
g.ALL("/user/list", func(r *ghttp.Request) {
|
||||
s.Group("/api.v2", func(group *ghttp.RouterGroup) {
|
||||
group.Middleware(MiddlewareAuth, MiddlewareCORS)
|
||||
group.ALL("/user/list", func(r *ghttp.Request) {
|
||||
r.Response.Write("list")
|
||||
})
|
||||
})
|
||||
|
||||
@ -332,8 +332,8 @@ func Test_Router_DomainGroup(t *testing.T) {
|
||||
p := ports.PopRand()
|
||||
s := g.Server(p)
|
||||
d := s.Domain("localhost, local")
|
||||
d.Group("/", func(g *ghttp.RouterGroup) {
|
||||
g.Group("/app", func(gApp *ghttp.RouterGroup) {
|
||||
d.Group("/", func(group *ghttp.RouterGroup) {
|
||||
group.Group("/app", func(gApp *ghttp.RouterGroup) {
|
||||
gApp.GET("/{table}/list/{page}.html", func(r *ghttp.Request) {
|
||||
intlog.Print("/{table}/list/{page}.html")
|
||||
r.Response.Write(r.Get("table"), "&", r.Get("page"))
|
||||
|
||||
@ -19,39 +19,39 @@ import (
|
||||
func Test_Router_Group_Group(t *testing.T) {
|
||||
p := ports.PopRand()
|
||||
s := g.Server(p)
|
||||
s.Group("/api.v2", func(g *ghttp.RouterGroup) {
|
||||
g.Middleware(func(r *ghttp.Request) {
|
||||
s.Group("/api.v2", func(group *ghttp.RouterGroup) {
|
||||
group.Middleware(func(r *ghttp.Request) {
|
||||
r.Response.Write("1")
|
||||
r.Middleware.Next()
|
||||
r.Response.Write("2")
|
||||
})
|
||||
g.GET("/test", func(r *ghttp.Request) {
|
||||
group.GET("/test", func(r *ghttp.Request) {
|
||||
r.Response.Write("test")
|
||||
})
|
||||
g.Group("/order", func(g *ghttp.RouterGroup) {
|
||||
g.GET("/list", func(r *ghttp.Request) {
|
||||
group.Group("/order", func(group *ghttp.RouterGroup) {
|
||||
group.GET("/list", func(r *ghttp.Request) {
|
||||
r.Response.Write("list")
|
||||
})
|
||||
g.PUT("/update", func(r *ghttp.Request) {
|
||||
group.PUT("/update", func(r *ghttp.Request) {
|
||||
r.Response.Write("update")
|
||||
})
|
||||
})
|
||||
g.Group("/user", func(g *ghttp.RouterGroup) {
|
||||
g.GET("/info", func(r *ghttp.Request) {
|
||||
group.Group("/user", func(group *ghttp.RouterGroup) {
|
||||
group.GET("/info", func(r *ghttp.Request) {
|
||||
r.Response.Write("info")
|
||||
})
|
||||
g.POST("/edit", func(r *ghttp.Request) {
|
||||
group.POST("/edit", func(r *ghttp.Request) {
|
||||
r.Response.Write("edit")
|
||||
})
|
||||
g.DELETE("/drop", func(r *ghttp.Request) {
|
||||
group.DELETE("/drop", func(r *ghttp.Request) {
|
||||
r.Response.Write("drop")
|
||||
})
|
||||
})
|
||||
g.Group("/hook", func(g *ghttp.RouterGroup) {
|
||||
g.Hook("/*", ghttp.HOOK_BEFORE_SERVE, func(r *ghttp.Request) {
|
||||
group.Group("/hook", func(group *ghttp.RouterGroup) {
|
||||
group.Hook("/*", ghttp.HOOK_BEFORE_SERVE, func(r *ghttp.Request) {
|
||||
r.Response.Write("hook any")
|
||||
})
|
||||
g.Hook("/:name", ghttp.HOOK_BEFORE_SERVE, func(r *ghttp.Request) {
|
||||
group.Hook("/:name", ghttp.HOOK_BEFORE_SERVE, func(r *ghttp.Request) {
|
||||
r.Response.Write("hook name")
|
||||
})
|
||||
})
|
||||
|
||||
@ -19,14 +19,14 @@ import (
|
||||
func Test_Router_Group_Hook1(t *testing.T) {
|
||||
p := ports.PopRand()
|
||||
s := g.Server(p)
|
||||
g := s.Group("/api")
|
||||
g.GET("/handler", func(r *ghttp.Request) {
|
||||
group := s.Group("/api")
|
||||
group.GET("/handler", func(r *ghttp.Request) {
|
||||
r.Response.Write("1")
|
||||
})
|
||||
g.ALL("/handler", func(r *ghttp.Request) {
|
||||
group.ALL("/handler", func(r *ghttp.Request) {
|
||||
r.Response.Write("0")
|
||||
}, ghttp.HOOK_BEFORE_SERVE)
|
||||
g.ALL("/handler", func(r *ghttp.Request) {
|
||||
group.ALL("/handler", func(r *ghttp.Request) {
|
||||
r.Response.Write("2")
|
||||
}, ghttp.HOOK_AFTER_SERVE)
|
||||
|
||||
|
||||
@ -77,14 +77,14 @@ func Test_Router_GroupBasic1(t *testing.T) {
|
||||
obj := new(GroupObject)
|
||||
ctl := new(GroupController)
|
||||
// 分组路由方法注册
|
||||
g := s.Group("/api")
|
||||
g.ALL("/handler", Handler)
|
||||
g.ALL("/ctl", ctl)
|
||||
g.GET("/ctl/my-show", ctl, "Show")
|
||||
g.REST("/ctl/rest", ctl)
|
||||
g.ALL("/obj", obj)
|
||||
g.GET("/obj/my-show", obj, "Show")
|
||||
g.REST("/obj/rest", obj)
|
||||
group := s.Group("/api")
|
||||
group.ALL("/handler", Handler)
|
||||
group.ALL("/ctl", ctl)
|
||||
group.GET("/ctl/my-show", ctl, "Show")
|
||||
group.REST("/ctl/rest", ctl)
|
||||
group.ALL("/obj", obj)
|
||||
group.GET("/obj/my-show", obj, "Show")
|
||||
group.REST("/obj/rest", obj)
|
||||
s.SetPort(p)
|
||||
s.SetDumpRouteMap(false)
|
||||
s.Start()
|
||||
@ -166,9 +166,9 @@ func Test_Router_GroupBuildInVar(t *testing.T) {
|
||||
obj := new(GroupObject)
|
||||
ctl := new(GroupController)
|
||||
// 分组路由方法注册
|
||||
g := s.Group("/api")
|
||||
g.ALL("/{.struct}/{.method}", ctl)
|
||||
g.ALL("/{.struct}/{.method}", obj)
|
||||
group := s.Group("/api")
|
||||
group.ALL("/{.struct}/{.method}", ctl)
|
||||
group.ALL("/{.struct}/{.method}", obj)
|
||||
s.SetPort(p)
|
||||
s.SetDumpRouteMap(false)
|
||||
s.Start()
|
||||
|
||||
@ -229,7 +229,7 @@ func TestTimer_AddLeveledEntry1(t *testing.T) {
|
||||
timer := New()
|
||||
array := garray.New(true)
|
||||
//glog.Println("start")
|
||||
timer.DelayAdd(1000*time.Millisecond, 1001*time.Millisecond, func() {
|
||||
timer.DelayAdd(1000*time.Millisecond, 1000*time.Millisecond, func() {
|
||||
//glog.Println("add")
|
||||
array.Append(1)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user