結構體類型 type 名字 struct{},下面這段是github.com/urfave/cli包裏的代碼,聲明瞭一個App的結構體類型html
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)git
cliApp := cli.NewApp()
cliApp.Name = "gocron"
cliApp.Usage = "gocron service"
這個cli包下的NewApp方法返回的是*App類型,所以cliApp就是能夠直接點操做裏面的成員了github
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, }