cols, err := rows.Columns() // Remember to check err afterwards
vals := make([]interface{}, len(cols))
for i, _ := range cols {
vals[i] = new(sql.RawBytes)
}
for rows.Next() {
err = rows.Scan(vals...)
// Now you can check each element of vals for nil-ness,
// and you can use type introspection and type assertions
// to fetch the column into a typed variable.
}
official original link
the official Demo is written like this, leaving three lines of comments at the bottom:
Now you can check each element of vals for nil-ness, and you can use type introspection and type assertions to fetch the column into a typed variable.
how on earth should this use type introspection and type assertions to fetch the column into a typed variable be implemented?
looked up a lot of data but couldn"t find the answer.
most of what is said on the Internet is (string) value reversal. Maybe these statements have been going on for some years. I can"t write like this now, and I will make a mistake.