我有来自数据库的数据:
[{
"name": "joseph",
"user": "admin"
},
{ "name": "george",
"user": "visitor"
},
{
"name": "thomas",
"user": "admin"
}]
我想找到带有url的用户,例如:/测试?q={"用户":"管理员"}
然后结果数据只有管理员。
首先,您的查询字符串应该遵循本文中提到的格式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