reflect.Value.Set using unaddressable value

后端 未结 3 2197
余生分开走
余生分开走 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 11:05

    In a very similar fashion to the accepted answer (but in a slightly different context), and an error that I keep making in different projects:

    func migrate(db *gorm.DB) {
        db.AutoMigrate(User{}, Activity{})
    }
    

    becomes

    func migrate(db *gorm.DB) {
        db.AutoMigrate(&User{}, &Activity{})
    }
    

    Notice the ampersands.

提交回复
热议问题