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

如何从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条)

报告相同问题?

悬赏问题

  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题
  • ¥15 Visual Studio问题
  • ¥20 求一个html代码,有偿
  • ¥100 关于使用MATLAB中copularnd函数的问题