繁体   English   中英

向Go Json Rest添加查询参数

[英]Adding query Parameters to Go Json Rest

我正在使用库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之上的一个薄包装,您是否看过该软件包的文档 具体来说, Request对象具有一个Form字段,其中包含解析后的查询字符串值映射以及POST数据,您可以将其作为url.Valuesmap[string][]string )进行访问,或者特别是从FormValue检索一个。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM