go命令行参数
舉例:打印name參數的值
package mainimport ("flag""fmt" )func main() {username := flag.String("name", "", "Input your username")flag.Parse()fmt.Println("Hello, ", *username) }
?
編譯:
? go_test go build flag.go
運行:如果沒有指定參數值,打印第三個說明的參數"Input your username"
? go_test ./flag -name flag needs an argument: -name Usage of ./flag:-name stringInput your username
如果指定參數值,打印結果
? go_test go run flag.go -name=welcome! Hello, welcome!?
把-name的值賦給了username
轉載于:https://www.cnblogs.com/liurong07/p/10512250.html
總結
- 上一篇: GAN_李弘毅讲解
- 下一篇: XGBoost的理解