This question already has an answer here:
I am referring to following method that takes last argument as args ...interfact{})
func (*sqlx.DB).Select(dest interface{}, query string, args ...interface{}) error
https://godoc.org/github.com/jmoiron/sqlx#DB.Select
From my understanding that the method accepts last parameter of any type which is variadic ..
So
selectStmt = 'Select * FROM users where user_id IN (?)'
selectStmt, userArgs, err := sqlx.In(selectStmt, userIDs)// userIDs is a slice
if err != nil {
return nil, errors.Wrap(err, "")
}
selectStmt = s.db.Rebind(selectStmt)
var users []User
err = s.db.Select(&users, selectStmt, userArgs) // wrong one .. Line A
err = s.db.Select(&users, selectStmt, userArgs... ) // right one .. Line B
In the aforementioned code if i comment out Line B , but not Line A it doesn't work. I get following error.
- sql: converting argument $1 type: unsupported type []interface {}, a slice of interface *
Question
What exactly happening here , why can't go infer the variadic automatically ?? What is the need of passing extra '...' to the third argument?
</div>