GET
url: http://127.0.0.1:8080/users/{id}
http://127.0.0.1:8080/users/1 对于id值的获取
package main
import (
	"github.com/gin-gonic/gin"
)
func main() {
	router := gin.Default()
	router.GET("/users/:id", func(c *gin.Context) {
		id := c.Param("id")
		c.JSON(200, gin.H{
			"id" : id,
		})
	})
	router.Run(":8080")
}
返回 {"id":"1"}
http://127.0.0.1:8080/users/1/2/3 对于id值的获取
package main
import (
	"github.com/gin-gonic/gin"
)
func main() {
	router := gin.Default()
	router.GET("/users/*id", func(c *gin.Context) {
		id := c.Param("id")
		c.JSON(200, gin.H{
			"id" : id,
		})
	})
	router.Run(":8080")
}
curl http://127.0.0.1:8080/users/1/2/3 返回 {"id":"/1/2/3"}
如果使用浏览器访问 http://127.0.0.1:8080/users 会返回 {"id":"/"} 这是因为请求被重定向了,如果设置 router.RedirectTrailingSlash = false 则禁止重定向
如果同时存在
func main() {
   router := gin.Default()
   router.GET("/users/*id", func(c *gin.Context) {
      id := c.Param("id")
      c.JSON(200, gin.H{
         "id" : id,
      })
   })
   router.GET("/users", func(c *gin.Context) {
      c.JSON(200, true)
   })
   router.Run(":8080")
}
curl http://127.0.0.1:8080/users 会返回 true
原文:https://www.cnblogs.com/juanmaofeifei/p/14274261.html