Skip to content

Instantly share code, notes, and snippets.

@xandout
Created July 19, 2017 18:02
Show Gist options
  • Save xandout/abe5a663edc6d78d92957aa83d6dde31 to your computer and use it in GitHub Desktop.
Save xandout/abe5a663edc6d78d92957aa83d6dde31 to your computer and use it in GitHub Desktop.
// defer rows.Close()
// colNames, err := rows.Columns()
// if err != nil {
// log.Fatal(err)
// }
// cols := make([]interface{}, len(colNames))
// colPtrs := make([]interface{}, len(colNames))
// for i := 0; i < len(colNames); i++ {
// colPtrs[i] = &cols[i]
// }
// for rows.Next() {
// var myMap = make(map[string]interface{})
// err = rows.Scan(colPtrs...)
// if err != nil {
// log.Fatal(err)
// }
// for i, col := range cols {
// myMap[colNames[i]] = col
// }
// // Do something with the map
// for key, val := range myMap {
// fmt.Println("Key:", key, "Value Type:", reflect.TypeOf(val))
// }
// }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment