If you are making a console based program, you may need to have some arguments passed to it. Below is a simple example of how to do this!
In Go, any command arguments passed to the your program are available via the os.Args slice. This can be looped over just like any other slice or array. It is usually worth skipping the first item as this contains the name of the exe.
The Go compiling guide explains the folder set up for a Go program, once that is done:
package main
import (
"fmt"
"os"
)
func main() {
// The first item is the program name
fmt.Println("Program name:", os.Args[0])
// Check if we have passed any arguments
if len(os.Args) > 1 {
for i, v := range os.Args {
// Not interested in the program name so skipping...
if i > 0 {
fmt.Println("Hi ", v, " Person #", i)
}
}
} else {
fmt.Println("Where is everyone?")
}
}
Updated (25/08/2026)