获取路径参数

时间:2020-06-17 17:24:24   收藏:0   阅读:59
func main() {
	router := gin.Default()

	// 如果最后还有一个/,说明后面还有一个参数,如果不写,就是空
	
	router.GET("/user/:name", func(c *gin.Context) {
		name := c.Param("name")
		c.String(http.StatusOK, "Hello %s", name)
	})
	
	router.GET("/user/:name/*action", func(c *gin.Context) {
		name := c.Param("name")
		action := c.Param("action")
		message := name + " is " + action
		c.String(http.StatusOK, message)
	})

	router.Run(":8080")

}

  

原文:https://www.cnblogs.com/yzg-14/p/13137783.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!