栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

Golang GAE-胡子的结构中的intID

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Golang GAE-胡子的结构中的intID

intID
是Key的内部属性,而不是struct,可以通过getter访问:

id := key.IntID()

GetAll
返回
[]*Key
,您没有使用它:

_, err := q.GetAll(c, &blogposts)

解决此问题的一种方法是创建一个既包含帖子信息又包含关键信息的viewmodel结构(未经测试,但这是要点):

  //... handler pre ...  keys, err := q.GetAll(c, &blogposts)  if err != nil {    http.Error(w, "Problem fetching posts.", http.StatusInternalServerError)    return  }  models := make([]BlogPostVM, len(blogposts))  for i := 0; i < len(blogposts); i++ {    models[i].Id = keys[i].IntID()    models[i].Title = blogposts[i].Title    models[i].Content = blogposts[i].Content  }  //... render with mustache ...}type BlogPostVM struct {  Id int  Title string  Content string}


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/484334.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号