# __ .______ __ __ .______ .___________. ______ ______ .___ ___. # | | | _ \ | | | | | _ \ | | / | / __ \ | \/ | # | | | |_) | | |__| | | |_) | `---| |----` | ,----'| | | | | \ / | # | | | ___/ | __ | | ___/ | | | | | | | | | |\/| | # | | | | | | | | | | | | __ | `----.| `--' | | | | | # |__| | _| |__| |__| | _| |__| (__) \______| \______/ |__| |__| # ""$o o$"" ""$o o$" o "$""""o "o $" o""" $" "$o "$o" $o " $ o$" "$o $$$o$$$$o$$$$ $" "oooo o "" ""$$$$$$$$""o"" oo oooo" "$$$$$$oo"oo$$$o" o$$$$oo" o$$$o "o$$$$$$$ "$ $$$$$$$$$oo o$$$$$$$$$o"$" $ $$$ $$$$$$ o$$$$$$ "$$o"o $ $$$$o $$$$$$ $$$$$$$ $$$$o"o $ $$$$$ $$$$$" "$$$$$ $$$$$$ $ $o""""" """" """ """"""$" $ o$$$$$"""$$$$$"$$$$$""$$$$$ooo"o $ o"$o $$$$$$$$oo$$$$$$$$o $$"" $ oo$ "$$$$$$$$$$$$$$$$$$$$" o" o $oo o$$$"$ $$o"o $$$$$$$"" "$$$$$$$ o$$ $$$$o IPHPT BUG o$$$$" $ $$$$ o "$$$$$oo o$$$$$$ "o$$$$ $ $$$$$ o$$"" $ $$$$$o" "$$$$$$$$$$$$$ o o$$$$$o$ "" $$ $$" $ $$$" o"o$$$$$$$$$$$$ " "$$$ $ $$o o$$ "o $$ " $$$$$$$$$$$"o "$$ $ $$$ $$$ oo$ $ o""$$""$$$o " $"o$o $$$o o$$$$ o$$$"o"$oo$$$$o" o $o $$$$$oo$ $$$$o $$$$ $$$$ $$$$" $ $$$$$"" $$ o$$$ """$$$$"o" "$$$o "$$$o $$$" o """ $ $$$oo $$$$o" $$ o$$$"o" """"$ o$$$ o$" $$$ $ "$"" o$"o"$$o$$$$ "$$"o" o$$ "$oo $ " $$o $ "oo$"o$$$"o$o"$$$$o" o" $$$ ""$o $$ $$$o "o$$o$"$$"$$o$$o$$"$$o" $$$ ""o $$$ ""$$$ $$$$$$ $$$$ $" $$$$ $$ $$$$ $$$$"$$$o$ $"" $$$ $$$$ "$$$ """ $$$$ $$"" "$$ oo$" $ooo $ "$$ wildcard route id conflicts with existing children in path   -  叶落山城秋

wildcard route id conflicts with existing children in path

panic: wildcard route ':id' conflicts with existing children in path '/console/post/:id/edit'

goroutine 1 [running]:
github.com/gin-gonic/gin.(*node).insertChild(0xc0000772c0, 0x1, 0xc00002996e, 0x8, 0xc000029960, 0x16, 0xc0001b25e0, 0x4, 0x4)
	/Users/zghua/web/go/src/github.com/gin-gonic/gin/tree.go:280 +0x73c
github.com/gin-gonic/gin.(*node).addRoute(0xc0000772c0, 0xc000029960, 0x16, 0xc0001b25e0, 0x4, 0x4)
	/Users/zghua/web/go/src/github.com/gin-gonic/gin/tree.go:237 +0x226
github.com/gin-gonic/gin.(*Engine).addRoute(0xc0000af9e0, 0x186ca49, 0x3, 0xc000029960, 0x16, 0xc0001b25e0, 0x4, 0x4)
	/Users/zghua/web/go/src/github.com/gin-gonic/gin/gin.go:256 +0x145
github.com/gin-gonic/gin.(*RouterGroup).handle(0xc0001a0880, 0x186ca49, 0x3, 0x1872678, 0x9, 0xc00000e620, 0x1, 0x1, 0x1967a01, 0xc00000e620)
	/Users/zghua/web/go/src/github.com/gin-gonic/gin/routergroup.go:75 +0x1d3
github.com/gin-gonic/gin.(*RouterGroup).GET(0xc0001a0880, 0x1872678, 0x9, 0xc00000e620, 0x1, 0x1, 0x1967a80, 0xc0001a0880)
	/Users/zghua/web/go/src/github.com/gin-gonic/gin/routergroup.go:103 +0x7c
github.com/izghua/go-blog/router.RoutersInit(0xc00008e058)
	/Users/zghua/web/go/src/github.com/izghua/go-blog/router/router.go:35 +0x68b
main.main()
	/Users/zghua/web/go/src/github.com/izghua/go-blog/main.go:18 +0x27
exit status 2

gin框架的路由的时候,报了错

因为项目要用 restful路由的形式,但是还是报错了..

httprouter 中使用的是显式匹配,所以在设计路由的时候需要规避一些会导致路由冲突的情况,例如:

conflict:
GET /user/info/:name
GET /user/:id

no conflict:
GET /user/info/:name
POST /user/:id

简单来讲的话,如果两个路由拥有一致的 http method (指 GET/POST/PUT/DELETE) 和请求路径前缀,且在某个位置出现了 A 路由是 wildcard (指 :id 这种形式) 参数,B 路由则是普通字符串,那么就会发生路由冲突。


欢迎转载,但请附上原文地址哦,尊重原创,谢谢大家 本文地址: https://www.iphpt.com/detail/123/
本站(PHP --> Golang)已重构,代码开源

当你能力不能满足你的野心的时候,你就该沉下心来学习