go flag使用

2023-03-24  本文已影响0人  xun2019

直接上代码

package main
import (
    "flag"
    "fmt"
)
func main() {
    // Define a bool flag
    boolArg := flag.Bool("sync", false, "This is a bool argument")
    stringArg := flag.String("des", "this is a string", "This is a bool argument")
    // Parse flag
    flag.Parse()
    fmt.Println("Bool Arg:", *boolArg)
    fmt.Println("String Arg:", *stringArg)
}

运行代码

go run main.go -sync -des="this is des"

说明

上一篇 下一篇

猜你喜欢

热点阅读