Skip to content

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

@matheus-meneses

Description

@matheus-meneses

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions