为什么我的存储实体使用默认值?

huangapple go评论67阅读模式
英文:

Why are my stored entities using default values?

问题

我正在说

data := Thing {
    date:     time.Now().UnixNano()   
    name:     "foo",
    value:    5,
}
_, err := datastore.Put(c, datastore.NewIncompleteKey(c, "stuff", nil), &data)
if err != nil {
    http.Error(w, err.Error(), http.StatusInternalServerError)
    return
}

存储的内容是{0, "", 0}。我期望看到类似{1366370653722376000, "foo", 5}的内容。我做错了什么?

注意:我正在使用开发服务器(dev appserver)。

英文:

I am saying

data := Thing {
    date:     time.Now().UnixNano()   
    name:     "foo",
    value:    5,
}
_, err := datastore.Put(c, datastore.NewIncompleteKey(c, "stuff", nil), &data)
if err != nil {
    http.Error(w, err.Error(), http.StatusInternalServerError)
    return
}

What is getting stored is {0, "", 0}. I expect to see something like {1366370653722376000, "foo", 5}. What am I doing wrong?

Note: I am using the dev appserver.

答案1

得分: 7

你必须导出你想要在包外可见的名称。为了实现这一点,你必须使用任何 Unicode 大写类的首字母(ASCII 大写字母是其中的一个子集),例如 Date 而不是 dateName 而不是 name,等等。

如果没有这样做,datastore.Put 将无法通过反射“看到”这些字段。

英文:

You must export the names you want to be visible outside your package. To achieve that you must use as its first letter any Unicode upper-case-class (which ASCII upper case letters are a subset), e.g. Date instead of date, Name instead of name, etc.

Without that the datastore.Put cannot "see" (using reflection) the fields.

huangapple
  • 本文由 发表于 2013年4月19日 19:28:38
  • 转载请务必保留本文链接:https://go.coder-hub.com/16103571.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定