Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

reflect.Value.Set using unaddressable value

Tags:

g.GET("/", func(c echo.Context) error {     var users []models.User     err := db.Find(users).Error     if err != nil {         fmt.Println(err)     }     return c.JSON(http.StatusOK, users) }) 

this is the code for getting and displaying users from table using slice is resulting following error from gorm

reflect.Value.Set using unaddressable value

like image 930
Krishna Satya Avatar asked Aug 22 '17 05:08

Krishna Satya


1 Answers

You have to call Find with a pointer to the slice.

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

relevant Gorm documentation: http://jinzhu.me/gorm/crud.html#query

like image 118
S. Diego Avatar answered Sep 26 '22 03:09

S. Diego