Reputation: 8744
I am trying to call this Gorp function http://godoc.org/github.com/coopernurse/gorp#DbMap.Get
I am doing this:
// ClassType
obj, err := c.Gorp.Get(entities.ClassType{}, class.ClassTypeCode)
if err != nil {
panic(err)
}
class.ClassType = obj.(*entities.ClassType) <<<<<<<<< Error here
My Class looks like this:
package entities
import (
"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
}
I keep getting this error message: interface conversion: interface is *entities.ClassType, not entities.ClassType
If I change my code to :
// ClassType
obj, err := c.Gorp.Get(entities.ClassType{}, class.ClassTypeCode)
if err != nil {
panic(err)
}
class.ClassType = obj.(*entities.ClassType)
I then get this message:
cannot use obj.(*entities.ClassType) (type *entities.ClassType) as type entities.ClassType in assignment
What am I doing wrong?
Upvotes: 0
Views: 172