Hi all,
Tried Googling, but can't find much ...
Withfunc Command(name string, arg ...string) *Cmd
Is there a way to pass a slice as the second parameter? I have an set of arguments for a command.
Cheers!
--
Nice example, Thanks :)
Didn't think I came across this reading effective ... might be worth popping in there?
--
Well perhaps that needs looking at. Go's spec, whilst far simpler than many other languages', is still quite a long document. Effective Go is certainly not a subset, but it does cover much of the same material - someone who has read the spec does not need to be told "The control structures of Go are related to those of C but differ in important ways".It's great that the definitive spec is so accessible, but I don't see that it should be read before "Effective Go".
Within the function Printf, v acts like a variable of type []interface{} but if it is passed to another variadic function, it acts like a regular list of arguments. Here is the implementation of the function log.Println we used above. It passes its arguments directly to fmt.Sprintln for the actual formatting.
// Println prints to the standard logger in the manner of fmt.Println.
func Println(v ...interface{}) {
std.Output(2, fmt.Sprintln(v...)) // Output takes parameters (int, string)
}
We write ... after v in the nested call to Sprintln to tell the compiler to treat v as a list of arguments; otherwise it would just pass v as a single slice argument.