作者:E4b9a6, 创建:2022-06-06, 字数:332, 已阅:105, 最后更新:2022-06-06
flag包,用于解析命令行参数,代码示例如下
package main
import (
"flag"
"fmt"
)
func main(){
var name = flag.String("name","chancel","input your name")
var age = flag.Int("age",10,"input your age")
flag.Parse()
fmt.Println("Hello ",*name," age:",*age)
}
// 输出
➜ go run main.go --name demo --age 18
Hello demo age: 18