Skip to content

Commit 45f4b78

Browse files
committed
fix: 修正行为解析bug
1 parent a0d5f26 commit 45f4b78

File tree

11 files changed

+51
-29
lines changed

11 files changed

+51
-29
lines changed

go.mod

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ require (
9797
github.com/jinzhu/inflection v1.0.0 // indirect
9898
github.com/jinzhu/now v1.1.5 // indirect
9999
github.com/json-iterator/go v1.1.12 // indirect
100-
github.com/julienschmidt/httprouter v1.3.0
101100
github.com/klauspost/compress v1.15.9 // indirect
102101
github.com/klauspost/cpuid/v2 v2.0.9 // indirect
103102
github.com/labstack/echo/v4 v4.10.0

go.sum

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -736,7 +736,6 @@ github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/X
736736
github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo=
737737
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
738738
github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
739-
github.com/julienschmidt/httprouter v1.3.0 h1:U0609e9tgbseu3rBINet9P48AI/D3oJs4dN7jwJOQ1U=
740739
github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM=
741740
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
742741
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=

pkg/adapter/fiberadapter/fiberadapter.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ func Adapter(b *builder.Engine, app *fiber.App) {
6565
app.Delete(v.Path, func(ctx *fiber.Ctx) error {
6666
return RouteAdapter(b, ctx)
6767
})
68+
case "Any":
69+
app.All(v.Path, func(ctx *fiber.Ctx) error {
70+
return RouteAdapter(b, ctx)
71+
})
6872
}
6973
}
7074
}

pkg/adapter/ginadapter/ginadapter.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ func Adapter(b *builder.Engine, app *gin.Engine) {
7575
app.DELETE(v.Path, func(ctx *gin.Context) {
7676
RouteAdapter(b, ctx)
7777
})
78+
case "Any":
79+
app.Any(v.Path, func(ctx *gin.Context) {
80+
RouteAdapter(b, ctx)
81+
})
7882
}
7983
}
8084
}

pkg/adapter/hertzadapter/hertzadapter.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ func Adapter(b *builder.Engine, r *server.Hertz) {
7373
r.DELETE(v.Path, func(c context.Context, ctx *app.RequestContext) {
7474
RouteAdapter(b, ctx)
7575
})
76+
case "Any":
77+
r.Any(v.Path, func(c context.Context, ctx *app.RequestContext) {
78+
RouteAdapter(b, ctx)
79+
})
7680
}
7781
}
7882
}

pkg/adapter/zeroadapter/zeroadapter.go

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ func RouteAdapter(b *builder.Engine, routePath string) http.HandlerFunc {
1919
context.SetFullPath(routePath)
2020

2121
b.Render(context)
22-
return
2322
}
2423
}
2524

@@ -34,11 +33,34 @@ func Adapter(b *builder.Engine, server *rest.Server) {
3433

3534
// 解析服务
3635
for _, v := range routePaths {
37-
routes = append(routes, rest.Route{
38-
Method: v.Method,
39-
Path: v.Path,
40-
Handler: RouteAdapter(b, v.Path),
41-
})
36+
if v.Method == "Any" {
37+
routes = append(routes, rest.Route{
38+
Method: http.MethodGet,
39+
Path: v.Path,
40+
Handler: RouteAdapter(b, v.Path),
41+
})
42+
routes = append(routes, rest.Route{
43+
Method: http.MethodPost,
44+
Path: v.Path,
45+
Handler: RouteAdapter(b, v.Path),
46+
})
47+
routes = append(routes, rest.Route{
48+
Method: http.MethodDelete,
49+
Path: v.Path,
50+
Handler: RouteAdapter(b, v.Path),
51+
})
52+
routes = append(routes, rest.Route{
53+
Method: http.MethodPut,
54+
Path: v.Path,
55+
Handler: RouteAdapter(b, v.Path),
56+
})
57+
} else {
58+
routes = append(routes, rest.Route{
59+
Method: v.Method,
60+
Path: v.Path,
61+
Handler: RouteAdapter(b, v.Path),
62+
})
63+
}
4264
}
4365

4466
server.AddRoutes(routes)

pkg/app/handler/admin/actions/delete.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package actions
22

33
import (
4-
"fmt"
5-
64
"github.com/quarkcms/quark-go/pkg/builder"
75
"github.com/quarkcms/quark-go/pkg/builder/actions"
86
"github.com/quarkcms/quark-go/pkg/msg"
@@ -62,7 +60,5 @@ func (p *Delete) Handle(ctx *builder.Context, model *gorm.DB) interface{} {
6260
return ctx.JSON(200, msg.Error(err.Error(), ""))
6361
}
6462

65-
fmt.Println("abcd")
66-
6763
return ctx.JSON(200, msg.Success("操作成功", "", ""))
6864
}

pkg/builder/engine.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,10 @@ func (p *Engine) routeMappingParser() {
378378
p.DELETE(routePath.Path, func(ctx *Context) error {
379379
return p.handleParser(ctx)
380380
})
381+
case "Any":
382+
p.Any(routePath.Path, func(ctx *Context) error {
383+
return p.handleParser(ctx)
384+
})
381385
}
382386
}
383387
}

pkg/builder/template/adminresource/handlers_action.go

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package adminresource
22

33
import (
4-
"fmt"
54
"reflect"
65
"strings"
76

@@ -49,24 +48,21 @@ func (p *ActionRequest) Handle(ctx *builder.Context) interface{} {
4948
GetUriKey(interface{}) string
5049
}).GetUriKey(dropdownAction)
5150

52-
fmt.Println(uriKey)
53-
fmt.Println(ctx.Param("uriKey"))
54-
fmt.Println(ctx.Param("uriKey") == uriKey)
55-
5651
if ctx.Param("uriKey") == uriKey {
5752
result = dropdownAction.(interface {
5853
Handle(*builder.Context, *gorm.DB) interface{}
5954
}).Handle(ctx, model)
55+
56+
return result
6057
}
6158
}
6259
} else {
63-
fmt.Println(uriKey)
64-
fmt.Println(ctx.Param("uriKey"))
65-
fmt.Println(ctx.Param("uriKey") == uriKey)
6660
if ctx.Param("uriKey") == uriKey {
6761
result = v.(interface {
6862
Handle(*builder.Context, *gorm.DB) interface{}
6963
}).Handle(ctx, model)
64+
65+
return result
7066
}
7167
}
7268
}

pkg/builder/template/adminresource/resource.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func (p *Template) TemplateInit() interface{} {
5151
// 注册路由映射
5252
p.GET(IndexRoute, "Render") // 后台增删改查,列表路由
5353
p.GET(EditableRoute, "Render") // 后台增删改查,表格行内编辑路由
54-
p.ANY(ActionRoute, "Render") // 后台增删改查,执行行为路由
54+
p.Any(ActionRoute, "Render") // 后台增删改查,执行行为路由
5555
p.GET(CreateRoute, "Render") // 后台增删改查,创建页面路由
5656
p.POST(StoreRoute, "Render") // 后台增删改查,创建方法路由
5757
p.GET(EditRoute, "Render") // 后台增删改查,编辑页面路由

pkg/builder/template/template.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,8 @@ func (p *AdminTemplate) AddRouteMapping(method string, path string, handlerName
5454
}
5555

5656
// ANY is a shortcut for router.Handle(http.MethodGet, path, handle)
57-
func (p *AdminTemplate) ANY(path string, handlerName string) {
58-
p.GET(path, handlerName)
59-
p.HEAD(path, handlerName)
60-
p.OPTIONS(path, handlerName)
61-
p.POST(path, handlerName)
62-
p.PUT(path, handlerName)
63-
p.PATCH(path, handlerName)
64-
p.DELETE(path, handlerName)
57+
func (p *AdminTemplate) Any(path string, handlerName string) {
58+
p.AddRouteMapping("Any", path, handlerName)
6559
}
6660

6761
// GET is a shortcut for router.Handle(http.MethodGet, path, handle)

0 commit comments

Comments
 (0)