我试图调用这个 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 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

}

我不断收到此错误消息:接口转换:接口是 *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

我究竟做错了什么?