How to call the Scan variadic function using reflection

后端 未结 4 2173
栀梦
栀梦 2020-12-23 01:45

I\'m looking to call the Rows.Scan() function using reflection. However it takes a variable number of pointers, but there are not a lot of source examples. I need to use r

4条回答
  •  时光说笑
    2020-12-23 02:31

    I don't think you need reflection for this - you can use a slice and the ... operator to pass multiple values to a variadic function.

    col := rows.Columns()
    vals := make([]interface{}, col)
    rows.Scan(vals...)
    

    I may be misunderstanding what you want to do though!

提交回复
热议问题