a cron library for go
译文:go的cron库
文档
安装
go get github.com/robfig/cron/v3
示例
main.go
package main import ( "fmt" "time" "github.com/robfig/cron/v3" ) func task() { now := time.Now() fmt.Println(now) } func main() { scheduler := cron.New() scheduler.AddFunc("* * * * *", task) scheduler.Start() defer scheduler.Stop() // 阻止主进程退出 select {} }
启动
$ go run main.go 2022-10-21 16:21:00.005327 +0800 CST m=+29.718695273 2022-10-21 16:22:00.005497 +0800 CST m=+89.717609279