Use the flag package to define variables, call flag.Parse(), and access the values directly.
package main
import (
"flag"
"fmt"
)
func main() {
name := flag.String("name", "World", "A greeting name")
count := flag.Int("count", 1, "Number of greetings")
flag.Parse()
for i := 0; i < *count; i++ {
fmt.Printf("Hello, %s\n", *name)
}
}
Run with go run main.go -name=Go -count=3.