package main import ( "github.com/gin-gonic/gin" "net/http" ) func main() { r:= gin.Default() r.GET("user/:name/:age", func(c *gin.Context) { name := c.Param("name") age :=c.Param("age") c.JSON(http.StatusOK,gin.H{ "Name":name, "Age":age, }) }) r.GET("/blog/:year/:month", func(c *gin.Context) { year :=c.Param("year") month := c.Param("month") c.JSON(http.StatusOK,gin.H{ "year":year, "month":month, }) }) r.Run(":9999") /* 访问输出: http://127.0.0.1:9999/user/stefan/22 { "Age": "12", "Name": "stefan" } */ /* http://127.0.0.1:9999/blog/2021/01 { "month": "01", "year": "2021" } */ }