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

Conflict when map path parameter and static url in same resource #2416

Closed
matheus-meneses opened this issue Jun 22, 2020 · 2 comments · Fixed by #2663
Closed

Conflict when map path parameter and static url in same resource #2416

matheus-meneses opened this issue Jun 22, 2020 · 2 comments · Fixed by #2663

Comments

@matheus-meneses
Copy link

matheus-meneses commented Jun 22, 2020

Description

Conflict map when use path parameter and static url in same url resource

How to reproduce

package main

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

func main() {
	g := gin.Default()
	g.GET("/path/:dynamicpath", func(c *gin.Context) {
		c.String(200, "Hello dynamic", c.Param("name"))
	})
	g.GET("/path/staticpath", func(c *gin.Context) {
		c.String(200, "Hello static", c.Param("name"))
	})

	g.Run(":9000")
}

Expectations

Both url's are mapping in Gin Engine

Actual result

panic: 'staticpath' in new path '/path/staticpath' conflicts with existing wildcard ':dynamicpath' in existing prefix '/path/:dynamicpath'

goroutine 1 [running]:
github.com/gin-gonic/gin.(*node).addRoute(0xc00046b110, 0xc0002cc456, 0xa, 0xc000302570, 0x6, 0x6)
        /Users/bi001189/go/pkg/mod/github.com/gin-gonic/gin@v1.6.3/tree.go:215 +0x152b
github.com/gin-gonic/gin.(*Engine).addRoute(0xc00013b900, 0xc00011fbe0, 0x3, 0xc0002cc450, 0x10, 0xc000302570, 0x6, 0x6)
        /Users/bi001189/go/pkg/mod/github.com/gin-gonic/gin@v1.6.3/gin.go:264 +0x1e7
github.com/gin-gonic/gin.(*RouterGroup).handle(0xc00013b900, 0xc00011fbe0, 0x3, 0xc00011fbb0, 0x10, 0xc000302570, 0x6, 0x6, 0x0, 0x0)
        /Users/bi001189/go/pkg/mod/github.com/gin-gonic/gin@v1.6.3/routergroup.go:75 +0x132
github.com/gin-gonic/gin.(*RouterGroup).Handle(0xc00013b900, 0xc00011fbe0, 0x3, 0xc00011fbb0, 0x10, 0xc000119840, 0x5, 0x8, 0x0, 0x0)
        /Users/bi001189/go/pkg/mod/github.com/gin-gonic/gin@v1.6.3/routergroup.go:93 +0x15d
main.registerGinEngine(0xc000121160, 0x11, 0x1, 0x101, 0xc000144480, 0x2, 0x2, 0x1, 0x1388, 0xc00010ed20, ...)

Environment

  • go version: 1.14.4
  • gin version (or commit ref): 1.6.3
  • operating system: macOS Catalina 10.15.5 (19F96)
@linvis
Copy link
Contributor

linvis commented Jun 25, 2020

see #2016

due to httprouter which gin used for url router, not support path parameter and static url in the same time

@valclark1
Copy link

I've encountered this issue also. I believe it's very counter-intuitive and hinders building semantic routes. Instead, I have to opt for a convoluted route pattern and have to consider if to replace gin...I wish they had a disclaimer in the Readme or even explain this issue in the routing section. I wouldn't have had to now consider less ideal routes because of the time cost to refactor.

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