由于某些原因,当我尝试将布尔数据存储在Google Apps数据存储区中时,它始终存储为false。我的实体定义如下:type Link struct { Name string //Coloquial label for link. Set by original User. ... isOpen bool //Tells us whether anyone can rewrite the link. Set by original User. isPerminant bool //Tells us whether link should be saved forever. isFlagged bool //Tells us whether the content has ever been flagged inappropriate.}我创建一个对象并分配值,如下所示://Create Link from form datal := Link{ Name: r.FormValue("name"), ... isOpen: r.FormValue("open")=="on", isPerminant: r.FormValue("perminant")=="on", isFlagged: r.FormValue("flagged")=="on",}我通过运行以下命令验证数据://Put the Link in the datastorelKey, err := datastore.Put(c, datastore.NewIncompleteKey(c, "Link", nil), &l)if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return}var newLink Linkif err = datastore.Get(c, lKey, &newLink); err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return}newLink output value: {[name] ... false false false}即使我为is [...]属性之一的真实值硬编码,它们仍然都为false!WHHHHHHYYYY ???
2 回答
森栏
TA贡献1810条经验 获得超5个赞
尝试大写Iin Is:
type Link struct {
Name string //Coloquial label for link. Set by original User.
IsOpen bool //Tells us whether anyone can rewrite the link. Set by original User.
IsPerminant bool //Tells us whether link should be saved forever.
IsFlagged bool //Tells us whether the content has ever been flagged inappropriate.
}
。
//Create Link from form data
l := Link{
Name: r.FormValue("name"),
IsOpen: r.FormValue("open") == "on",
IsPerminant: r.FormValue("perminant") == "on",
IsFlagged: r.FormValue("flagged") == "on",
}
要将字段保存到数据存储,必须将其导出。即以大写字母开头。有关更多信息,请阅读Effective Go的“名称”部分
- 2 回答
- 0 关注
- 212 浏览
添加回答
举报
0/150
提交
取消