I have it working well by listing the individual conditions.  But I have a 
bunch of functions that do similar things (authenticate a user based on 
their email and password, get a list of users based on role and active 
status, get an individual user based on ID, etc.) and I was looking to 
combine them into a more generalized function.  So far I have not found a 
way.

On Sunday, May 17, 2020 at 6:39:07 PM UTC-4, Steven Hartland wrote:
>
> Did you use the correct calling convension e.g.
> db.Query(query, cond...)
>
> The ... makes the slice variadic, passing echData.Active, exchData.Role 
> instead of just a interface slice
>
> On 17/05/2020 23:27, Saied Seghatoleslami wrote:
>
> I hate to dig up something from 2012, but I have come across a similar 
> issue where I can use an explanation.  The signature of the Query function 
> in the sql package is: 
>
> func (db *DB <https://golang.org/pkg/database/sql/#DB>) Query(query string 
> <https://golang.org/pkg/builtin/#string>, args ...interface{}) (*Rows 
> <https://golang.org/pkg/database/sql/#Rows>, error 
> <https://golang.org/pkg/builtin/#error>)
>
>
> so, one would assume that passing something like this  for args would work 
> (Active is bool and Role is a string:
>
> var cond = []interface{}{exchData.Active, exchData.Role}
>
> but it does not, it results in this error:
>
> sql: converting argument $1 type: unsupported type []interface {}, a 
> slice of interface
>
> I suspect there is a good explanation for this that I do not get.
>
>
>
> On Friday, September 7, 2012 at 4:45:07 PM UTC-4, Paddy Foran wrote: 
>>
>> Consider the following: 
>>
>> In package fmt: func Println(a …interface{})
>>
>> One would think the following code would work:
>>
>> func main() {
>> testslice := []string { "this", "is", "a", "test" }
>> fmt.Println(testslice…)
>> }
>>
>> One would subsequently be met with "cannot use testslice (type []string) 
>> as type []interface {} in function argument" (
>> http://play.golang.org/p/H3349TDJnS)
>>
>> On the other hand, if one were to try:
>>
>> func print(words …string) {
>> for _, word := range words {
>> fmt.Printf("%s", word)
>> }
>> }
>>
>> func main() {
>> testslice := []string { "this", "is", "a", "test" }
>> print(testslice…)
>> }
>>
>> Everything works as expected (http://play.golang.org/p/1ZnIwge19V). Can 
>> anyone explain why the empty interface in variadic parameters prevents me 
>> from using argument expansion?
>>
>> God, I hope I used the right names for all these things.
>>
> -- 
> You received this message because you are subscribed to the Google Groups 
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to golan...@googlegroups.com <javascript:>.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/golang-nuts/1cc28db0-98c6-49cd-bd3e-7752ef2b5328%40googlegroups.com
>  
> <https://groups.google.com/d/msgid/golang-nuts/1cc28db0-98c6-49cd-bd3e-7752ef2b5328%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/262da5fc-ccbb-43f3-838f-2d4f04a43200%40googlegroups.com.

Reply via email to