gin获取路径中的参数
生活随笔
收集整理的這篇文章主要介紹了
gin获取路径中的参数
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
?gin獲取路徑中的參數
func main() {router := gin.Default()// 此規則能夠匹配/user/john這種格式,但不能匹配/user/ 或 /user這種格式router.GET("/user/:name", func(c *gin.Context) {name := c.Param("name")c.String(http.StatusOK, "Hello %s", name)})// 但是,這個規則既能匹配/user/john/格式也能匹配/user/john/send這種格式// 如果沒有其他路由器匹配/user/john,它將重定向到/user/john/router.GET("/user/:name/*action", func(c *gin.Context) {name := c.Param("name")action := c.Param("action")message := name + " is " + actionc.String(http.StatusOK, message)})router.Run(":8080") }總結
以上是生活随笔為你收集整理的gin获取路径中的参数的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: gin自定义日志格式
- 下一篇: 程序员笑话二十六