经验首页 前端设计 程序设计 Java相关 移动开发 数据库/运维 软件/图像 大数据/云计算 其他经验
当前位置:技术经验 » 程序设计 » Go语言 » 查看文章
[Go] gocron源码阅读-go语言的结构体
来源:cnblogs  作者:陶士涵  时间:2019/11/15 8:58:48  对本文有异议

结构体类型 type 名字 struct{},下面这段是github.com/urfave/cli包里的代码,声明了一个App的结构体类型

  1. type App struct {
  2. // The name of the program. Defaults to path.Base(os.Args[0])
  3. Name string
  4. // Full name of command for help, defaults to Name
  5. HelpName string
  6. // Description of the program.
  7. Usage string
  8. // Text to override the USAGE section of help
  9. UsageText string
  10. // Description of the program argument format.
  11. ArgsUsage string
  12. // Version of the program
  13. Version string
  14. // Description of the program
  15. Description string
  16. // List of commands to execute
  17. Commands []*Command
  18. // List of flags to parse
  19. Flags []Flag
  20. }

 


点操作符也可以和指向结构体的指针一起工作,如果赋给的是个指针,那也可以直接用点来操作
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就是可以直接点操作里面的成员了

  1. return &App{
  2. Name: filepath.Base(os.Args[0]),
  3. HelpName: filepath.Base(os.Args[0]),
  4. Usage: "A new cli application",
  5. UsageText: "",
  6. Version: "0.0.0",
  7. BashComplete: DefaultAppComplete,
  8. Action: helpCommand.Action,
  9. Compiled: compileTime(),
  10. Writer: os.Stdout,
  11. }

 

原文链接:http://www.cnblogs.com/taoshihan/p/11860759.html

 友情链接:直通硅谷  点职佳  北美留学生论坛

本站QQ群:前端 618073944 | Java 606181507 | Python 626812652 | C/C++ 612253063 | 微信 634508462 | 苹果 692586424 | C#/.net 182808419 | PHP 305140648 | 运维 608723728

W3xue 的所有内容仅供测试,对任何法律问题及风险不承担任何责任。通过使用本站内容随之而来的风险与本站无关。
关于我们  |  意见建议  |  捐助我们  |  报错有奖  |  广告合作、友情链接(目前9元/月)请联系QQ:27243702 沸活量
皖ICP备17017327号-2 皖公网安备34020702000426号