I want my function to take optional arguments in an efficent way.
Reading similar posts led me to variadic args and I'm trying to implement it alongside the flag package (simply looking for any alternative to the users being able to run available command line flags of their choice.. This is my flag package usage:
func main() {
var target string
var method string
flag.StringVar(&target, "target", "http://google.com/robots.txt", "Target address")
flag.StringVar(&method, "method", "GET", "Method")
flag.Parse()
requests.MakeRequest(target, method)
}
This is an example of variadic args function:
func foo(params ...int) {
fmt.Println(len(params))
}
func main() {
foo()
foo(1)
foo(1, 2, 3)
}
Can I combine the two? If this is not possible - how can I pass main program's user given arguments to a variadic function then?