reflect.Value.Set using unaddressable value

后端 未结 3 2199
余生分开走
余生分开走 2021-02-13 10:36
g.GET(\"/\", func(c echo.Context) error {
    var users []models.User
    err := db.Find(users).Error
    if err != nil {
        fmt.Println(err)
    }
    return c.JSO         


        
3条回答
  •  太阳男子
    2021-02-13 10:39

    Just to add clarification to S.Diego answers, changing this:

    err := db.Find(users).Error
    

    to this:

    err := db.Find(&users).Error
    

    the error says, the variable users is not addressable, because it is not a pointer.

提交回复
热议问题