[英]Adding query Parameters to Go Json Rest
I am using the library go-json-rest. 我正在使用库go-json-rest。 I'm trying to recognize queries parameters in the code for example localhost:8080/reminders?hello=world I want to access {hello: world} . 我试图识别代码中的查询参数,例如localhost:8080 / reminders?hello = world我想访问{hello:world}。 I have the following code: 我有以下代码:
//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)
}
I know that r.PathParams holds the url parameters but I cannot seem to find how to the query parameters past the "?" 我知道r.PathParams拥有url参数,但是我似乎找不到如何通过“?”查询参数的方法。 in the url. 在网址中。
Given that go-json-rest is a thin wrapper on top of net/http
, have you looked at that package's documentation ? 鉴于go-json-rest是net/http
之上的一个薄包装,您是否看过该软件包的文档 ? Specifically, the Request object has a field Form
that contains a parsed map of query string values as well as POST
data, that you can access as a url.Values
( map[string][]string
), or retrieve one in particular from FormValue
. 具体来说, Request对象具有一个Form
字段,其中包含解析后的查询字符串值映射以及POST
数据,您可以将其作为url.Values
( map[string][]string
)进行访问,或者特别是从FormValue
检索一个。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.