Go explain the main package of language learning

Explain the main pack of ### Go language learning

1.Go the main function does not support any return value
2. The status may be returned os.Exit (0)

func main(){
    fmt.Println("hellow world")
    os.Exit(0)
}

Function does not support parameter passing 3.main
4 may be acquired by command line parameters in the program os.Args

func main(){
    if len(os.Args) > 1{     //判断命令行参数数组长度是否大于1,输出命令行参数
        fmt.Println(os.Args[1])
    }
    fmt.Println("hellow world")
}
//执行
go run main.go alisleepy
//最终结果
alisleepy  hellow world

Guess you like

Origin www.cnblogs.com/alisleepy/p/11200312.html