結構體型別 type 名字 struct{},下面這段是github.com/urfave/cli包里的代碼,宣告了一個App的結構體型別
type App struct { // The name of the program. Defaults to path.Base(os.Args[0]) Name string // Full name of command for help, defaults to Name HelpName string // Description of the program. Usage string // Text to override the USAGE section of help UsageText string // Description of the program argument format. ArgsUsage string // Version of the program Version string // Description of the program Description string // List of commands to execute Commands []*Command // List of flags to parse Flags []Flag}
點運算子也可以和指向結構體的指標一起作業,如果賦給的是個指標,那也可以直接用點來操作
type User struct{
Name string
}
user:=&User{Name:"taoshihan"}
fmt.Println(user.Name)
cliApp := cli.NewApp()
cliApp.Name = "gocron"
cliApp.Usage = "gocron service"
這個cli包下的NewApp方法回傳的是*App型別,因此cliApp就是可以直接點操作里面的成員了
return &App{ Name: filepath.Base(os.Args[0]), HelpName: filepath.Base(os.Args[0]), Usage: "A new cli application", UsageText: "", Version: "0.0.0", BashComplete: DefaultAppComplete, Action: helpCommand.Action, Compiled: compileTime(), Writer: os.Stdout, }
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/65064.html
標籤:Go
