如何在golang中从查询localhost:8000/example?q={"user":"admin"}获取值
时间:2024-04-15
浏览:412
作者:佚名
有志者,事竟成!如果你在学习Golang,那么本文《如何在golang中从查询localhost:8000/example?q={"user":"admin"}获取值》,就很适合你!文章讲解的知识点主要包括,若是你对本文感兴趣,或者是想搞懂其中某个知识点,就请你继续往下看吧~
问题内容
我有来自数据库的数据:
[{
"name": "joseph",
"user": "admin"
},
{ "name": "george",
"user": "visitor"
},
{
"name": "thomas",
"user": "admin"
}]
我想通过 url 查找用户,例如:../testing?q={"user":"admin"}
然后结果数据仅管理。
正确答案
首先,您的查询字符串应遵循此 https://en.wikipedia.org/wiki/Query_string 中提到的格式
// r is *http.Request
r.URL.Query().Get("user") // this will provide the value of user in the query
这对于您的用例来说应该足够了,但有关更多详细信息,您可以参考 https://golangbyexample.com/net-http-package-get-query-params-golang
理论要掌握,实操不能落!以上关于《如何在golang中从查询localhost:8000/example?q={"user":"admin"}获取值》的详细介绍,大家都掌握了吧!如果想要继续提升自己的能力,那么就来关注golang学习网公众号吧!
本文内容来源于互联网,如有侵权请联系删除。
近期热门
11.18
11.15
站内热门
最新文章
11.20
11.20
11.20
11.20
热门专题
