golang flag示例

golang flag示例

golang flag 包是用来解析命令行参数的.

package main

import (
    "flag"
    "fmt"
)

func test_flag() {
    data_path := flag.String("D", "/home/manu/sample/", "DB data path")
    log_file := flag.String("l", "/home/manu/sample.log", "log file")
    nowait_flag := flag.Bool("W", false, "do not wait until operation completes")

    flag.Parse()

    fmt.Println(*data_path)
    fmt.Println(*log_file)
    fmt.Println(*nowait_flag)
}

func main() {
    test_flag()
}

/*
result:
robert-homedeMacBook-Pro:flag robert-home$ go run test_flag.go -D "Hello" -l "robert"
Hello
robert
false
*/
阅读更多
版权声明:http://blog.csdn.net/robertkun https://blog.csdn.net/robertkun/article/details/78966820
文章标签: golang flag
个人分类: golang
上一篇golang toml解析
下一篇golang实现Http Server
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭
关闭