Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

net/ghttp: hooks calling order does not meet expectations #4178

Open
canbusio opened this issue Mar 2, 2025 · 0 comments
Open

net/ghttp: hooks calling order does not meet expectations #4178

canbusio opened this issue Mar 2, 2025 · 0 comments
Labels
bug It is confirmed a bug, but don't worry, we'll handle it.

Comments

@canbusio
Copy link

canbusio commented Mar 2, 2025

Go version

1.23.6

GoFrame version

2.8.3

Can this bug be reproduced with the latest release?

Option Yes

What did you do?

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"

	"fmt"
)

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.BindHookHandler("/demo/{num}", ghttp.HookBeforeServe, handler1())
			s.BindHookHandler("/demo/:num", ghttp.HookBeforeServe, handler2())
			s.Run()
			return nil
		},
	}
)

func handler1() func(r *ghttp.Request) {
	return func(r *ghttp.Request) {
		fmt.Println(1)
	}
}
func handler2() func(r *ghttp.Request) {
	return func(r *ghttp.Request) {
		fmt.Println(2)
	}
}

What did you see happen?

2
1

What did you expect to see?

1
2

{num} should before :num

@canbusio canbusio added the bug It is confirmed a bug, but don't worry, we'll handle it. label Mar 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug It is confirmed a bug, but don't worry, we'll handle it.
Projects
None yet
Development

No branches or pull requests

1 participant