I'm trying to read data from a MySQL database from my Go app.
var queryStr string = "SELECT * FROM Customers"
rows, err := db.Query(queryStr)
defer rows.Close()
for rows.Next() {
// do stuffs
}
The query it's ok and it works; now I'd like to easily map each record of the MySQL query to a Customer object that I've previuosly defined as showed below:
type Customer struct {
id IntegerType `json:"id"`
name string `json:"name"`
surname string `json:"surname"`
}
How can I do that?
Second question: once I get an array of Customer object how can I easily put it into a new JSON object under a specific key called "data"?
thanks for your support :)