将 URL 查询变量中的数组发送到用 Go 编写的服务器
我需要向使用 gendry 的 golang 服务器发送带有查询的 HTTP 请求 SQL 库。不幸的是,我没有关于服务器如何实现的确切信息。
当涉及到简单的查询时,没有问题:
/api/resource
/api/resource?where={"age >=": 18}
...
但是,我需要使用limit
和offset
。为此,有一个 _limit
属性,它应该是一个由 2 个数字(偏移量和限制)组成的数组。该库的代码有一部分:
if val, ok := where["_limit"]; ok {
arr, ok := val.([]uint) // first is offset, second is limit.
}
问题是,如何通过 URL 查询字符串发送数组,这样它才能工作?我尝试了多种方法,但每种方法都返回错误,例如:
// [builder] the value of "_limit" must be of []uint type
/api/path?where={"_limit": [0, 10]}
I need to send a HTTP request with query to a golang server that uses gendry SQL library. Unfortunately, I don't have exact info about how the server is implemented.
When it comes to a simple query, there is no problem with it:
/api/resource
/api/resource?where={"age >=": 18}
...
However, I need to use limit
and offset
. For this, there is a _limit
property, which should be an array of 2 numbers (offset and limit). There is a part of the library's code:
if val, ok := where["_limit"]; ok {
arr, ok := val.([]uint) // first is offset, second is limit.
}
The question is, how can I send an array through URL query string, so it will work? I tried several ways, but each returned an error, eg:
// [builder] the value of "_limit" must be of []uint type
/api/path?where={"_limit": [0, 10]}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在http中,你可以指定一个重复参数的参数数组。
您的服务器应该会看到
limit["0","10"]
。您可以使用指向 postbin 的简单curl 请求来验证这一点,例如 https://hookbin.com/In http, you can specify an array of parameters be repeating the parameter.
Your server should see
limit["0","10"]
. You can verify this with a simple curl request pointed a postbin such as https://hookbin.com/