我试图调用这个 Gorp 函数http://godoc.org/github.com/coopernurse/gorp#DbMap.Get我正在这样做: // ClassType obj, err := c.Gorp.Get(entities.ClassType{}, class.ClassTypeCode) if err != nil { panic(err) } class.ClassType = obj.(*entities.ClassType) <<<<<<<<< Error here我的班级看起来像这样:package entitiesimport ( "time")type Class struct { Id int ClassTypeCode string VideoPath string VideoSize int Duration float64 CreatedAt time.Time VisibleAt time.Time NoLongerVisibleAt time.Time // Relationships ClassType ClassType Instructor User Equipment []Equipment}我不断收到此错误消息:接口转换:接口是 *entities.ClassType,而不是 entity.ClassType如果我将代码更改为: // ClassType obj, err := c.Gorp.Get(entities.ClassType{}, class.ClassTypeCode) if err != nil { panic(err) } class.ClassType = obj.(*entities.ClassType)然后我收到这条消息:cannot use obj.(*entities.ClassType) (type *entities.ClassType) as type entities.ClassType in assignment我究竟做错了什么?
- 1 回答
- 0 关注
- 262 浏览
添加回答
举报
0/150
提交
取消