How can golang sql get rid of the problem that the parameters of Scan must correspond to the columns returned by the query one by one?

  golang, question

This problem is difficult to describe in one sentence in the title.
Specifically:
For the row found, only the Scan method can be used to obtain the value.
However, the Scan method must insert the parameters into the query column one by one to obtain the value.
One more and one less will return error
For example, sql is select col1,col2,col3.
You must first var col1, col2, col3
Then row.Scan(&col1, &col2, &col3)

If I want to build such a simple wheel:
Enter an sql statement as a parameter (no matter how many values the sql statement queries) to return an array or key-value pair of results.

Since I don’t know how many columns are select in sql, and QueryRow().Scan () must fill in parameters one by one, how can I achieve the desired effect?

If there is already a ready-made wheel, I can go to the source code to learn.

Acquire by reflection
You can refer to this:https://github.com/jinzhu/gor …