Belajar Command Line Arguments Golang
Golang punya package called as Args
Args adalah string berbentuk array berisi command line arguments
Examples:
The first argument
package main import ( "fmt" "os" ) func main() { // The first argument is always program name myProgramName := os.Args[0] // it will display the program name fmt.Println(myProgramName) }
Output:
Get all arguments
package main import ( "fmt" "os" ) func main() { allArgs := os.Args[1:] fmt.Println(allArgs) }
Output: