添加查询参数以转到Json Rest
我正在使用库go json rest。我试图识别代码中的查询参数,例如localhost:8080/members?hello=world我想访问{hello:world}。我有以下代码:添加查询参数以转到Json Rest,json,rest,go,query-parameters,json-api,Json,Rest,Go,Query Parameters,Json Api,我正在使用库go json rest。我试图识别代码中的查询参数,例如localhost:8080/members?hello=world我想访问{hello:world}。我有以下代码: //in another function &rest.Route{"GET", "/reminders", i.GetAllReminders}, func (i *Impl) GetAllReminders(w rest.ResponseWriter, r *rest.Request) {
//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参数,但我似乎找不到如何将查询参数超过url中的“?”。鉴于go json rest是
net/http
之上的一个薄包装器,您看过了吗?具体来说,它有一个字段Form
,其中包含查询字符串值的解析映射以及POST
数据,您可以通过url.values
(map[string][]string
)访问这些数据,或者从FormValue中检索一个数据。几小时后我找到了它。它被藏在那个参数里。r、 URL.Query()。我是个新手,很难识别源代码中的接口。谢谢