gogf / gf

GoFrame is a modular, powerful, high-performance and enterprise-class application development framework of Golang.
https://goframe.org
MIT License
11.79k stars 1.61k forks source link

There is an issue with batch registration of ALLMap using routing packets in version v2 #3096

Open ceroot opened 1 year ago

ceroot commented 1 year ago

1. What version of Go and system type/arch are you using?

go version go1.21.3 windows/amd64

2. What version of GoFrame are you using?

gf -v GoFrame CLI Tool v2.5.6, https://goframe.org/ GoFrame Version: v2.5.6 in current go.mod

3. Can this issue be re-produced with the latest release?

yes

4. What did you do?

Code in api/user/v1/user.go

package v1

import (
    "github.com/gogf/gf/v2/frame/g"
)

type InfoReq struct {
    g.Meta `path:"/info" tags:"info" method:"post" summary:"info"`
}
type InfoRes struct{}

type EditReq struct {
    g.Meta `path:"/edit" tags:"info" method:"post" summary:"edit"`
}
type EditRes struct{}

type AddReq struct {
    g.Meta `path:"/add" tags:"info" method:"post" summary:"add"`
}
type AddRes struct{}

Code in internal/cmd/cmd.go

package cmd

import (
    "context"

    "github.com/gogf/gf/v2/frame/g"
    "github.com/gogf/gf/v2/net/ghttp"
    "github.com/gogf/gf/v2/os/gcmd"

    "demo/internal/controller/hello"
    "demo/internal/controller/user"
)

var (
    Main = gcmd.Command{
        Name:  "main",
        Usage: "main",
        Brief: "start http server",
        Func: func(ctx context.Context, parser *gcmd.Parser) (err error) {
            s := g.Server()
            s.Group("/", func(group *ghttp.RouterGroup) {
                group.Middleware(ghttp.MiddlewareHandlerResponse)
                group.Bind(
                    hello.NewV1(),
                )
            })

            s.Group("/api", func(group *ghttp.RouterGroup) {
                group.ALLMap(g.Map{
                    "/user": user.NewV1(), // 用户
                })
            })

            s.Run()
            return nil
        },
    }
)

5. What did you expect to see?

疑问:生成的路由ROUTE里没有把批量注册里的/user加进去,不知是系统这样设计的还是出现的bug。 我的理解是应该把/user加到路由里去,比如: /api/add应该生成/api/user/add。 ADDRESS METHOD ROUTE HANDLER MIDDLEWARE
:8080 ALL /* github.com/gogf/gf/v2/net/ghttp.internalMiddlewareServerTracing GLOBAL MIDDLEWARE
---------- -------- ------------ ----------------------------------------------------------------- ----------------------------------
:8080 ALL /api.json github.com/gogf/gf/v2/net/ghttp.(*Server).openapiSpec
---------- -------- ------------ ----------------------------------------------------------------- ----------------------------------
:8080 POST /api/user/add demo/internal/controller/user.(*ControllerV1).Add
---------- -------- ------------ ----------------------------------------------------------------- ----------------------------------
:8080 POST /api/user/edit demo/internal/controller/user.(*ControllerV1).Edit
---------- -------- ------------ ----------------------------------------------------------------- ----------------------------------
:8080 POST /api/user/info demo/internal/controller/user.(*ControllerV1).Info
---------- -------- ------------ ----------------------------------------------------------------- ----------------------------------
:8080 GET /hello demo/internal/controller/hello.(*ControllerV1).Hello ghttp.MiddlewareHandlerResponse
---------- -------- ------------ ----------------------------------------------------------------- ----------------------------------
:8080 ALL /swagger/* github.com/gogf/gf/v2/net/ghttp.(*Server).swaggerUI HOOK_BEFORE_SERVE
---------- -------- ------------ ----------------------------------------------------------------- ----------------------------------

6. What did you see instead?

ADDRESS METHOD ROUTE HANDLER MIDDLEWARE
:8080 ALL /* github.com/gogf/gf/v2/net/ghttp.internalMiddlewareServerTracing GLOBAL MIDDLEWARE
---------- -------- ------------ ----------------------------------------------------------------- ----------------------------------
:8080 ALL /api.json github.com/gogf/gf/v2/net/ghttp.(*Server).openapiSpec
---------- -------- ------------ ----------------------------------------------------------------- ----------------------------------
:8080 POST /api/add demo/internal/controller/user.(*ControllerV1).Add
---------- -------- ------------ ----------------------------------------------------------------- ----------------------------------
:8080 POST /api/edit demo/internal/controller/user.(*ControllerV1).Edit
---------- -------- ------------ ----------------------------------------------------------------- ----------------------------------
:8080 POST /api/info demo/internal/controller/user.(*ControllerV1).Info
---------- -------- ------------ ----------------------------------------------------------------- ----------------------------------
:8080 GET /hello demo/internal/controller/hello.(*ControllerV1).Hello ghttp.MiddlewareHandlerResponse
---------- -------- ------------ ----------------------------------------------------------------- ----------------------------------
:8080 ALL /swagger/* github.com/gogf/gf/v2/net/ghttp.(*Server).swaggerUI HOOK_BEFORE_SERVE
---------- -------- ------------ ----------------------------------------------------------------- ----------------------------------
gqcn commented 1 year ago

@ceroot Yes, it's designed so, but it might be improved.