package main
import "github.com/gin-gonic/gin"
func main() {
r := gin.Default()
r.GET("/:p/a.gif", func(c *gin.Context) {
c.JSON(200, gin.H{
"message": "pong",
})
})
r.POST("/:p/a.gif", func(c *gin.Context) {
c.JSON(200, gin.H{
"message": "pong",
})
})
r.GET("/:p/b.gif", func(c *gin.Context) {
c.JSON(200, gin.H{
"message": "pong",
})
})
r.POST("/:p/b.gif", func(c *gin.Context) {
c.JSON(200, gin.H{
"message": "pong",
})
})
r.GET("/:p/c.gif", func(c *gin.Context) {
c.JSON(200, gin.H{
"message": "pong",
})
})
r.POST("/:p/c.gif", func(c *gin.Context) {
c.JSON(200, gin.H{
"message": "pong",
})
})
r.GET("/:p/all.gif", func(c *gin.Context) {
c.JSON(200, gin.H{
"message": "pong",
})
})
r.POST("/:p/all.gif", func(c *gin.Context) {
c.JSON(200, gin.H{
"message": "pong",
})
})
r.Run() // listen and serve on 0.0.0.0:8080 (for windows "localhost:8080")
}
$ curl -X GET localhost:8080/a/p.gif
404 not found
$ curl -X GET localhost:8080/a/p.gif
curl: (52) Empty reply from server
[GIN-debug] [WARNING] Creating an Engine instance with the Logger and Recovery middleware already attached.
[GIN-debug] [WARNING] Running in "debug" mode. Switch to "release" mode in production.
- using env: export GIN_MODE=release
- using code: gin.SetMode(gin.ReleaseMode)
[GIN-debug] GET /:p/a.gif --> main.main.func1 (3 handlers)
[GIN-debug] POST /:p/a.gif --> main.main.func2 (3 handlers)
[GIN-debug] GET /:p/b.gif --> main.main.func3 (3 handlers)
[GIN-debug] POST /:p/b.gif --> main.main.func4 (3 handlers)
[GIN-debug] GET /:p/c.gif --> main.main.func5 (3 handlers)
[GIN-debug] POST /:p/c.gif --> main.main.func6 (3 handlers)
[GIN-debug] GET /:p/all.gif --> main.main.func7 (3 handlers)
[GIN-debug] POST /:p/all.gif --> main.main.func8 (3 handlers)
[GIN-debug] Environment variable PORT is undefined. Using port :8080 by default
[GIN-debug] Listening and serving HTTP on :8080
2021/09/22 18:27:14 http: panic serving 127.0.0.1:60804: runtime error: slice bounds out of range [:2] with capacity 1
goroutine 20 [running]:
net/http.(*conn).serve.func1()
/Users/xinlingchao/sdk/go1.17.1/src/net/http/server.go:1801 +0xb9
panic({0x136afa0, 0xc000312240})
/Users/xinlingchao/sdk/go1.17.1/src/runtime/panic.go:1047 +0x266
github.com/gin-gonic/gin.(*node).getValue(0x600, {0xc00031222c, 0x203000}, 0xc000128840, 0x0)
/Users/xinlingchao/.go/pkg/mod/github.com/gin-gonic/[email protected]/tree.go:481 +0xd70
github.com/gin-gonic/gin.(*Engine).handleHTTPRequest(0xc000328d00, 0xc0001c0c00)
/Users/xinlingchao/.go/pkg/mod/github.com/gin-gonic/[email protected]/gin.go:482 +0x195
github.com/gin-gonic/gin.(*Engine).ServeHTTP(0xc000328d00, {0x1415bf0, 0xc0003401c0}, 0xc0001c0b00)
/Users/xinlingchao/.go/pkg/mod/github.com/gin-gonic/[email protected]/gin.go:445 +0x1c5
net/http.serverHandler.ServeHTTP({0xc0003440f0}, {0x1415bf0, 0xc0003401c0}, 0xc0001c0b00)
/Users/xinlingchao/sdk/go1.17.1/src/net/http/server.go:2878 +0x43b
net/http.(*conn).serve(0xc00031ae60, {0x1418be0, 0xc000344000})
/Users/xinlingchao/sdk/go1.17.1/src/net/http/server.go:1929 +0xb08
created by net/http.(*Server).Serve
/Users/xinlingchao/sdk/go1.17.1/src/net/http/server.go:3033 +0x4e8
Description
How to reproduce
Expectations
Actual result
Gin traceback:
Environment