嘿,我试图通过传递 id 来获取实体,但看起来我得到了一个nill 指针, 我试图以几种方式初始化实体,但结果是一样的。我正在尝试尽可能多地创建我的服务器,就像这个示例 待办事项我在这里缺少什么?type UserManager struct { users []*Users user *Users}func NewUserManager() *UserManager { return &UserManager{}} func (userManager *UserManager) putUser(c appengine.Context, u *Users) (usreRes *Users, err error) {key, err := datastore.Put(c, datastore.NewIncompleteKey(c, "users", nil), u)if err != nil { return nil, err }c.Debugf("file key inserted :%#v", key)return u, nil}func (userManager *UserManager) getUserById(userKey string, c appengine.Context) (usreRes *Users, err error) {entity_id_int, err := strconv.ParseInt(userKey, 10, 64)if err != nil { return userManager.user, err}k := datastore.NewKey(c, "users", "", entity_id_int, nil)userRes := new(Users)err = datastore.Get(c, k, &userRes)//err = datastore.Get(c, k, &userManager.user)if err != nil { return userManager.user, err}//return userManager.user,nilreturn userRes, nil}
- 1 回答
- 0 关注
- 184 浏览
添加回答
举报
0/150
提交
取消