json - 将查询参数添加到 Go Json Rest

标签 json rest go query-parameters json-api

我正在使用库 go-json-rest。我正在尝试识别代码中的查询参数,例如 localhost:8080/reminders?hello=world 我想访问 {hello: world} 。我有以下代码:

//in another function
&rest.Route{"GET", "/reminders", i.GetAllReminders},

func (i *Impl) GetAllReminders(w rest.ResponseWriter, r *rest.Request) {
    reminders := []Reminder{}
    i.DB.Find(&reminders)
    w.WriteJson(&reminders)
}

我知道 r.PathParams 包含 url 参数,但我似乎无法找到如何通过“?”查询参数。在网址中。

最佳答案

考虑到 go-json-rest 是 net/http 之上的薄包装器,您是否看过 that package's documentation ?具体来说,the Request object有一个 Form 字段,其中包含查询字符串值的解析映射以及 POST 数据,您可以将其作为 url.Values 访问( map[string][]string),或者从 FormValue 中检索一个。

关于json - 将查询参数添加到 Go Json Rest,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28635895/

相关文章:

javascript - 如何删除在 jquery 中使用 .append() 创建的 div?

javascript - 比较两个对象数组

json - 如何在 Go 中动态处理 JSON 响应中缺失的字段

go - 等待一个协程完成

javascript - 文件对象在推送到数组时变成字符串? JS

java - 如何从我的 Android 设备访问本地 REST API?

ssl - 对 IIS 中托管的 HTTPS WebAPI 的 Java 应用程序调用

去 atomic.AddFloat32()

go - 如何在不更改golang中原始值的情况下修改对象的值副本?

java - 返回没有参数化参数的通用列表