I use GORM in my project and I want to create something like DB admin page.
To load records I send GET with params:
category: "name", // database table name
On server I have the next code:
func LoadItems(db *gorm.DB, category string) interface{} {
var items interface{}
loadItems := func(i interface{}) {
err := db.Find(i).Error
if err != nil {
panic(err)
}
items = i
}
switch category {
case "groups":
var records []*models.Groups
loadItems(&records)
case "departments":
var records []*models.Departments
loadItems(&records)
case .....
........
}
return items
}
Is it possible to replace switch
because I have 10 tables and after record editing I send new data to server, where I re forced to use switch
in other function to save it.