go-zero
go-zero copied to clipboard
go-zero 可以支持查询数组?can go-zero support querying arrays?
如图,我需要制作一个批量删除内容的接口,目前期望的地址是批量传递一些ids。如下图:
通过api的配置如下
如你所见,他报错了。请问我的做法正确嘛?
我自己在logic中处理是可以获取到的
请问有什么好的办法吗?我希望在api中自动生成以便使用
There is no need to use [] in the tag, only the type is defined as an array, and the incoming is separated by commas. example:
articlesDelReq {
ids []int `form:"ids,optional"`
}
Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑🤝🧑👫🧑🏿🤝🧑🏻👩🏾🤝👨🏿👬🏿
english please :(
There is no need to use [] in the tag, only the type is defined as an array, and the incoming is separated by commas. example:
articlesDelReq { ids []int `form:"ids,optional"` }
thanks for your help。but i try it doesn't work
you can see this feedback
this is ok but get value is null
this is my article.api
so,it is something wrong?
Looking forward to your help again
very thanks
Sorry, I confirmed it, and it is determined that form passing arrays is not supported in zero. There are two ways to solve it.
- Pass the string in the form and decode it in the business.
- Pass the body.
Sorry, I confirmed it, and it is determined that form passing arrays is not supported in zero. There are two ways to solve it.
- Pass the string in the form and decode it in the business.
- Pass the body.
Thanks for your help again. I know how to get it to work. The only thing left to do is wait for an official fix.
目前 go-zero 是支持form 数组的,参考写法如下: api 文件
articlesDelReq {
ids []int `form:"ids,optional"`
}
对于 GET 方法,你可以通过如下格式访问:
http://{baseURL}{path}?ids=[1,2,3]
对于 POST 方法,你可以通过如下格式访问:
http://{baseURL}{path}
| key | value |
|---|---|
| ids | [1,2,3] |
最终,你将获取到 ids 为1,2,3的数组
Currently go-zero supports form arrays, the reference is as follows: Api file
articlesDelReq {
ids []int `form:"ids,optional"`
}
For HttpMethodGet, you can write as follows:
http://{baseURL}{path}?ids=[1,2,3]
And for HttpMethodPost, you can write as follows:
http://{baseURL}{path}
| key | value |
|---|---|
| ids | [1,2,3] |
Finally, you will get an array with ids
1,2,3
This issue is stale because it has been open for 30 days with no activity.
This issue was closed because it has been inactive for 14 days since being marked as stale.