我正在使用库 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/