How do I access command-line arguments in Go? They’re not passed as arguments to main.
A complete program, possibly created by linking multiple packages, must have one package called main, with a function
func main() { ... }defined. The function main.main() takes no arguments and returns no value.
You can access the command-line arguments using the
os.Argsvariable. For example,You can also use the flag package, which implements command-line flag parsing.