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

Catch-all route has multiple catch-all in another way #2192

Open
authhwang opened this issue Dec 23, 2019 · 1 comment
Open

Catch-all route has multiple catch-all in another way #2192

authhwang opened this issue Dec 23, 2019 · 1 comment

Comments

@authhwang
Copy link

Description

After seeing all of related issues and source code, i know it is illegal that a path has multiple catch-all node. so

In way a:

r.GET("/cmd/:user/*info/*action", func(c *gin.Context) {
		fmt.Println("enter /cmd/:user/*info/*action")
})

Result:

It will throw a error saying "catch-all routes are only allowed at the end of the path in path '/cmd/:user/*info/*action'".

In way b:

r.GET("/cmd/:user/*info", func(c *gin.Context) {
		fmt.Println("enter /cmd/:name/*info")
})

r.GET("/cmd/:user/*info/*action", func(c *gin.Context) {
                fmt.Println("enter /cmd/:user/*info/*action")
})

Reuslt:

It work successfully.

How to reproduce

package main

import (
	"github.com/gin-gonic/gin"
)

func main() {
	r := gin.Default()

	r.GET("/cmd/:user/*info", func(c *gin.Context) {
               fmt.Println("enter /cmd/:name/*info")
	})

	r.GET("/cmd/:user/*info/*action", func(c *gin.Context) {
		fmt.Println("enter /cmd/:name/*info/*action")
	})

	r.GET("/cmd/:user/*info/*action/*test", func(c *gin.Context) {
		fmt.Println("enter /cmd/:name/*info/*action/*test")
	})
	
	r.Run(":8080")
}

Expectations

get a error in terminal like way a.

Actual result

[GIN-debug] GET    /cmd/:user/*info          --> main.main.func1 (3 handlers)
[GIN-debug] GET    /cmd/:user/*info/*action  --> main.main.func2 (3 handlers)
[GIN-debug] GET    /cmd/:user/*info/*action/*test --> main.main.func3 (3 handlers)
[GIN-debug] Listening and serving HTTP on :8080

run successfully with gin.

Environment

  • go version: go1.13.4
  • gin version (or commit ref): v1.5.0
  • operating system: windows/amd64
@authhwang
Copy link
Author

please use newer code, i forget to import fmt package. sorry.

package main

import (
        "fmt"
	"github.com/gin-gonic/gin"
)

func main() {
	r := gin.Default()

	r.GET("/cmd/:user/*info", func(c *gin.Context) {
               fmt.Println("enter /cmd/:name/*info")
	})

	r.GET("/cmd/:user/*info/*action", func(c *gin.Context) {
		fmt.Println("enter /cmd/:name/*info/*action")
	})

	r.GET("/cmd/:user/*info/*action/*test", func(c *gin.Context) {
		fmt.Println("enter /cmd/:name/*info/*action/*test")
	})
	
	r.Run(":8080")
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant