go-zero icon indicating copy to clipboard operation
go-zero copied to clipboard

go-zero 可以支持查询数组?can go-zero support querying arrays?

Open daifuyang opened this issue 3 years ago • 6 comments

如图,我需要制作一个批量删除内容的接口,目前期望的地址是批量传递一些ids。如下图: image 通过api的配置如下 172761661922151_ pic 如你所见,他报错了。请问我的做法正确嘛? 我自己在logic中处理是可以获取到的 image 请问有什么好的办法吗?我希望在api中自动生成以便使用

daifuyang avatar Aug 31 '22 05:08 daifuyang

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"`
}

MarkJoyMa avatar Aug 31 '22 06:08 MarkJoyMa

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


english please :(

Issues-translate-bot avatar Aug 31 '22 07:08 Issues-translate-bot

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 image image this is ok but get value is null image this is my article.api image image image so,it is something wrong? Looking forward to your help again very thanks

daifuyang avatar Aug 31 '22 07:08 daifuyang

Sorry, I confirmed it, and it is determined that form passing arrays is not supported in zero. There are two ways to solve it.

  1. Pass the string in the form and decode it in the business.
  2. Pass the body.

MarkJoyMa avatar Aug 31 '22 10:08 MarkJoyMa

Sorry, I confirmed it, and it is determined that form passing arrays is not supported in zero. There are two ways to solve it.

  1. Pass the string in the form and decode it in the business.
  2. 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.

daifuyang avatar Aug 31 '22 12:08 daifuyang

目前 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

kesonan avatar Sep 12 '22 14:09 kesonan

This issue is stale because it has been open for 30 days with no activity.

github-actions[bot] avatar Sep 13 '23 01:09 github-actions[bot]

This issue was closed because it has been inactive for 14 days since being marked as stale.

github-actions[bot] avatar Mar 15 '24 01:03 github-actions[bot]