使用chi路由器在golang API上进行过滤。

huangapple go评论81阅读模式
英文:

Filtering on golang API using chi router

问题

我正在使用GO和chi路由器尝试创建一个通过状态筛选表格的端点,但是当我在URL中使用**?**时,我收到了404页面未找到的错误。

我正在使用以下代码:

r.Get("/table?status={status}", l.Hanlder(tableHandler.GetByStatus))

当我移除**?**时,它可以正常工作。我不能使用它进行筛选吗?我不能,我该怎么做?

提前感谢。

英文:

I'm using GO and chi router trying to create and endpoint filtering a table by status, but when I use the ? on the URL I'm receiving 404 page not found.

I am using the following code:

r.Get("/table?status={status}", l.Hanlder(tableHandler.GetByStatus))

When I remove the ? it works just well. I can't use it to filter? I can not, how can I do it?

Thanks in advance.

答案1

得分: 1

你可以使用URLParamURLParamFromCtx函数来获取查询字符串参数的值。

英文:

You can use the URLParam or URLParamFromCtx function to get the value of a query string parameter.

huangapple
  • 本文由 发表于 2021年6月9日 23:01:29
  • 转载请务必保留本文链接:https://go.coder-hub.com/67906796.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定