I am traing to abstract a rest API with go lang but i totally stuck in the reflection part.
log.Printf("handleIndex resourceType = %v", res.resourceType)
slice := reflect.MakeSlice(reflect.SliceOf(res.resourceType), 0, 0)
err := res.api.DB.Select(&slice, "SELECT * FROM domains")
if err != nil {
log.Printf("SQL Error %s", err)
}
fmt.Printf("\n=================================== \n%#v \n=================================== ", slice)
resourceType is a reflect.Type of the model
res.api.DB is sqlx.DB
Output of the code is :
handleIndex resourceType = main.Domain
SQL Error expected slice but got struct
[]main.Domain{}
so basically even i make a slice of reflect.Type i got a struct What i am missing ?
Aucun commentaire:
Enregistrer un commentaire