我正在为我的路线使用 gorilla 多路复用器并传递一个 id。
如何使用该 ID 从数据存储中获取实体。
param := mux.Vars(r)
c := appengine.NewContext(r)
item := []Item{}
pr, err := datastore.NewQuery("Item").Filter("ID = ", param["id"]).GetAll(c, &item)
我被卡住了,我尝试使用过滤器但它不起作用。
接下来我要做什么?
最佳答案
有了id就不用查询了。一种更快、更便宜的方法是创建一个键并直接从数据存储中检索该实体。
https://cloud.google.com/appengine/docs/go/datastore/entities#Go_Retrieving_an_entity
关于google-app-engine - 通过id获取实体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26556788/