I just begin to learn Go, and have a problem with returning ref vars from function
I have a function to get rows from a DB table:
func getData(query string, db *sql.DB) *sql.Rows {
rows, err := db.Query(query)
if err != nil {
fmt.Println("SQL select error: ")
log.Fatal(err)
}
defer rows.Close()
return rows
}
now I try to get data from db
rows := getData("select * from all_obrash", db)
fmt.Println(rows)
I expect it just returns *sql.Rows
but I get nothing
&{0xc00025e100 0x4cf270 0xc0002743c0 <nil> 0xc000248180 {{0 0} 0 0 0 0} true <nil> []}
When I call from main()
it works just fine, but when I move code to func
it stop get rows, I think I miss something here.