前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >[Go] gocron源码阅读-go语言的结构体

[Go] gocron源码阅读-go语言的结构体

作者头像
唯一Chat
发布2019-11-15 12:12:57
3410
发布2019-11-15 12:12:57
举报
文章被收录于专栏:陶士涵的菜地陶士涵的菜地

结构体类型 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,
    }
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2019-11-14 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档