13.08-解析命令列參數
go run myfile.gogo run -v myfile.gopackage main
import ("fmt";"flag";"math/rand")
func main() {
// Define flags
maxp := flag.Int("max", 6, "the max value")
// Parse
flag.Parse()
// Generate a number between 0 and max
fmt.Println(rand.Intn(*maxp))
}Last updated