dongwang3066 2016-12-22 09:02
浏览 3488
已采纳

如何从go * gin.context对象获取所有查询参数

I am looking at https://godoc.org/github.com/gin-gonic/gin documentation for a method which returns list of all the query parameters passed. There are methods which return value of a query parameter. Is there any method which returns list of all the query parameters passed ? It's ok if we don't get values. I am fetching the values of the query parameter using the following code. But this code can only check if the query parameter exists or not.

func myHandler(c *gin.Context) {

    // check for query params
    if queryParam, ok := c.GetQuery("startingIndex"); ok {
        if queryParam == "" {
            c.Header("Content-Type", "application/json")
            c.JSON(http.StatusNotFound,
                gin.H{"Error: ": "Invalid startingIndex on search filter!"})
            c.Abort()
            return
        }
    }
}
  • 写回答

2条回答 默认 最新

  • duanjipiao7076 2016-12-22 09:22
    关注

    You should be able to do c.Request.URL.Query() which will return a Values which is a map[string][]string

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥50 微信聊天记录备份到电脑提示成功了,但还是没同步到电脑微信
  • ¥15 python怎么在已有视频文件后添加新帧
  • ¥20 虚幻UE引擎如何让多个同一个蓝图的NPC执行一样的动画,
  • ¥15 fluent里模拟降膜反应的UDF编写
  • ¥15 MYSQL 多表拼接link
  • ¥15 关于某款2.13寸墨水屏的问题
  • ¥15 obsidian的中文层级自动编号
  • ¥15 同一个网口一个电脑连接有网,另一个电脑连接没网
  • ¥15 神经网络模型一直不能上GPU
  • ¥20 wpf datagrid单元闪烁效果失灵