我正在使用庫(kù) go-json-rest。我正在嘗試識(shí)別代碼中的查詢(xún)參數(shù),例如 localhost:8080/reminders?hello=world 我想訪問(wèn) {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 參數(shù),但我似乎無(wú)法找到如何通過(guò)“?”查詢(xún)參數(shù)。在網(wǎng)址中。
1 回答

料青山看我應(yīng)如是
TA貢獻(xiàn)1772條經(jīng)驗(yàn) 獲得超8個(gè)贊
鑒于 go-json-rest 是在 之上的一個(gè)薄包裝net/http
,你有沒(méi)有看過(guò)那個(gè)包的文檔?具體來(lái)說(shuō),Request 對(duì)象有一個(gè)字段Form
,其中包含查詢(xún)字符串值和POST
數(shù)據(jù)的解析映射,您可以將其作為url.Values
( map[string][]string
)訪問(wèn),或者特別是從 中檢索一個(gè)FormValue
。
- 1 回答
- 0 關(guān)注
- 192 瀏覽
添加回答
舉報(bào)
0/150
提交
取消