如何在数据存储中定义键类型?

How to define a Key type in datastore?

我有一个用户类型:

type User struct {
  Username     string
  Email        string
  Password     string
}

还有一个 post 种类:

type Post struct {
  User               // how to define here?
  Title        string
  Content      string
}

Post 实体看起来像:

用户:密钥(用户,'10000')

标题:"some tilte"

内容:"some content"

如何定义Post.User?

由于您的 Post 实体包含完整的 Key,请使用 datastore.Key 作为字段类型:

type Post struct {
    User    *datastore.Key
    Title   string
    Content string
}