Golang将结构分配给另一个结构字段不起作用

I am trying to use Gorp to get all gym classes. Gym classes have a class type so I run a second query to retrieve them. I get all the class types back, but the final assingment is not working for some reason.

package entities

import (
    "fmt"
    "github.com/coopernurse/gorp"
    "time"
)

type Class struct {
    Id                int
    ClassTypeId       int
    ClassType         ClassType
    VideoPath         string
    VideoSize         int
    Duration          float64
    CreatedAt         time.Time
    VisibleAt         time.Time
    NoLongerVisibleAt time.Time
}

func LatestClasses(dbmap *gorp.DbMap) *[]Class {
    var classes []Class
    query := "SELECT * FROM Class"

    _, err := dbmap.Select(&classes, query)
    if err != nil {
        panic(err)
    }

    for _, class := range classes {
        classTypeForClass(dbmap, &class)
    }

    return &classes
}

func classTypeForClass(dbmap *gorp.DbMap, class *Class) {
    var classType ClassType
    query := "SELECT * FROM ClassType "
    query += "WHERE Id=?"

    err := dbmap.SelectOne(&classType, query, class.ClassTypeId)
    if err != nil {
        panic(err)
    }
    fmt.Println(classType) <<<<<<<<<<< Lists Yoga, Pilates etc.
    class.ClassType = classType <<<<<<<< Seemingly does nothing

}

UPDATE

The ClassType struct looks like this:

package entities

import (
    "time"
)

type ClassType struct {
    Id           int
    Code         string
    Name         string
    InstructorId int
    CreatedAt    time.Time
}

ANOTHER UPDATE

I display the data as follows:

<h1>
    Latest Classes
</h1>
<hr/>


{{ range .}}
    {{.VideoPath}}
    <br>
    {{.ClassType.Name}}
    <br>
    {{.VideoSize}}
    <br>
    {{.Duration}}
    <br>
    {{.CreatedAt}}
    {{.NoLongerVisibleAt}}
<br><br>
{{end}}

The assignment works properly, but you are not assigning it to the proper object: In your loop

for _, class := range classes { classTypeForClass(dbmap, &class) }

class is a copy of the elements in the classes slice. Your classTypeForClass(dbmap, &class) properly assigns the class to this copy and the copy is discarded at the end of the loop body.

Try something like

for i := range classes {
    classTypeForClass(dbmap, &(classes[i]))
}

or maybe nicer: Have classTypeForClass return the class and just assign it like

for i := range classes {
    classes[i].ClassType = classTypeForClass(dbmap, &(classes[i]))
}

(Maybe even passing class as a value, not as a pointer.)