gpt4 book ai didi

json - 将查询参数添加到 Go Json Rest

转载 作者:IT王子 更新时间:2023-10-29 02:05:30 25 4
gpt4 key购买 nike

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

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com