Skip to content

Instantly share code, notes, and snippets.

@khan-rizwan
Created January 3, 2018 15:36
Show Gist options
  • Save khan-rizwan/4aa0e4d7cb4df8d6a86e139939577ef3 to your computer and use it in GitHub Desktop.
Save khan-rizwan/4aa0e4d7cb4df8d6a86e139939577ef3 to your computer and use it in GitHub Desktop.
How to pass a slice as a variadic input?
package main
import (
"fmt"
)
func echo(strings []int) []interface{} {
ids := []interface{}{}
for _, s := range strings {
ids = append(ids, s)
}
return ids
}
func vardic(val ...interface{}){
fmt.Println(val)
}
func main() {
i := []int{1,2,3}
fmt.Println("Hello",i)
vardic(echo(i)...)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment