获取Get中的参数

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

	// 匹配的url格式:  /welcome?firstname=Jane&lastname=Doe

	router.GET("/welcome", func(c *gin.Context) {
		// 如果没有这个key,就给一个默认值
		firstname := c.DefaultQuery("firstname", "Guest")
		lastname := c.Query("lastname") // 是 c.Request.URL.Query().Get("lastname") 的简写

		c.String(http.StatusOK, "Hello %s %s", firstname, lastname)
	})
	router.Run(":8080")
}

  

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

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