zoukankan      html  css  js  c++  java
  • go命令行参数

    举例:打印name参数的值

    package main
    
    import (
      "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 string Input your username

      

    如果指定参数值,打印结果

    ➜  go_test go run flag.go -name=welcome!
    Hello,  welcome!
    

    把-name的值赋给了username

    大道至简
  • 相关阅读:
    Qt图片显示
    C# 对话框使用整理
    C# AutoResetEvent 使用整理
    C++ 模板
    superset使用
    superset部署
    kafka修改topic副本数
    c# 生成自定义图片
    c# 解决Randoms伪随机重复问题
    c# 图片加水印
  • 原文地址:https://www.cnblogs.com/liurong07/p/10512250.html
Copyright © 2011-2022 走看看