I am writing code and I need it to catch the arguments and pass them through fmt.Println
(I want its default behavior to write arguments separated by spaces, and then a new line). However, []interface {} is required, but flag.Args() returns a []string .
Here is a sample code:
package main import ( "fmt" "flag" ) func main() { flag.Parse() fmt.Println(flag.Args()...) }
This returns the following error:
./example.go:10: cannot use args (type []string) as type []interface {} in function argument
This is mistake? Can't fmt.Println take any array ? By the way, I also tried to do this:
var args = []interface{}(flag.Args())
but I get the following error:
cannot convert flag.Args() (type []string) to type []interface {}
Is there a βGo Toβ way to get around this?
type-conversion go
cruizh Oct 20 '12 at 16:19 2012-10-20 16:19
source share