[日常] gocron源码阅读-使用go mod管理依赖源码启动gocron

从 Go1.11 开始,golang 官方支持了新的依赖管理工具go mod
go mod download: 下载依赖的 module 到本地 cache
go mod edit: 编辑 go.mod
go mod graph: 打印模块依赖图
go mod init: 在当前目录下初始化 go.mod(就是会新建一个 go.mod 文件)
go mod tidy: 整理依赖关系,会添加丢失的 module,删除不需要的 module
go mod vender: 将依赖复制到 vendor 下
go mod verify: 校验依赖
go mod why: 解释为什么需要依赖

以gocron为例,go get 下载代码后进入代码的目录执行 go mod tidy
会在我的$GOPATH/pkg/mod/cache/下载依赖的文件

进入gocron下载的目录src/github.com/ouqiang/gocron/cmd/gocron
执行go run gocron.go ,就可以运行起源码的gocron

gocron中的go.mod文件内容

module github.com/ouqiang/gocron

go 1.12

require (
    github.com/Tang-RoseChild/mahonia v0.0.0-20131226213531-0eef680515cc
    github.com/Unknwon/com v0.0.0-20190321035513-0fed4efef755 // indirect
    github.com/cihub/seelog v0.0.0-20170130134532-f561c5e57575
    github.com/dgrijalva/jwt-go v3.2.0+incompatible
    github.com/go-gomail/gomail v0.0.0-20160411212932-81ebce5c23df
    github.com/go-macaron/binding v0.0.0-20170611065819-ac54ee249c27
    github.com/go-macaron/gzip v0.0.0-20160222043647-cad1c6580a07
    github.com/go-macaron/inject v0.0.0-20160627170012-d8a0b8677191 // indirect
    github.com/go-macaron/toolbox v0.0.0-20180818072302-a77f45a7ce90
    github.com/go-sql-driver/mysql v1.4.1
    github.com/go-xorm/builder v0.3.4 // indirect
    github.com/go-xorm/core v0.6.2
    github.com/go-xorm/xorm v0.7.1
    github.com/golang/protobuf v1.3.1
    github.com/jakecoffman/cron v0.0.0-20190106200828-7e2009c226a5
    github.com/klauspost/compress v1.5.0 // indirect
    github.com/klauspost/cpuid v1.2.1 // indirect
    github.com/lib/pq v1.1.1
    github.com/ouqiang/goutil v1.1.1
    github.com/rakyll/statik v0.1.6
    github.com/sirupsen/logrus v1.4.2
    github.com/urfave/cli v1.20.0
    golang.org/x/crypto v0.0.0-20190530122614-20be4c3c3ed5 // indirect
    golang.org/x/net v0.0.0-20190522155817-f3200d17e092
    golang.org/x/text v0.3.2 // indirect
    google.golang.org/genproto v0.0.0-20190530194941-fb225487d101 // indirect
    google.golang.org/grpc v1.21.0
    gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc // indirect
    gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df // indirect
    gopkg.in/ini.v1 v1.42.0
    gopkg.in/macaron.v1 v1.3.2
)

 

posted @ 2019-11-13 21:29  唯一客服系统开发笔记  阅读(870)  评论(0编辑  收藏  举报