go 执行文件,参数解析,并且运用

package main

import (
	"flag"
	"fmt"
)

var names = flag.String("name","张三","名称")//申明变量,设置初始值,并且备注说明
var age = flag.Uint64("age",121,"年龄")
var sex = flag.String("sex","男","性别")


type Preson struct {
     names string
     sex   string
     age   uint64
}
var po Preson

func NewsetConfig(names,sex string, age uint64) Preson{
   po.names = names
   po.sex   = sex
   po.age   = age
  return po
}

func main(){
	//flag.Parse()
        fmt.Println(*names)
	fmt.Println(*age)
	fmt.Println(*sex)
	po :=NewsetConfig(*names,*sex,*age)
	fmt.Println(po)
}

  

 

posted on 2021-12-23 17:55  kevin_yang123  阅读(64)  评论(0编辑  收藏  举报