1

我正在使用库 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 参数,但我似乎无法找到如何通过“?”查询参数。在网址中。

4

1 回答 1

2

鉴于 go-json-rest 是一个薄包装器net/http,你看过那个包的文档吗?具体来说,Request 对象有一个字段Form,其中包含查询字符串值和POST数据的解析映射,您可以将其作为url.Values( map[string][]string) 访问,或者特别从 中检索一个FormValue

于 2015-02-21T21:09:14.277 回答