package monitors import ( "github.com/robfig/cron/v3" "log" ) type MonitorHelper struct { CronStr string Cron *cron.Cron } func (the *MonitorHelper) initial() { the.Cron = cron.New() log.Printf("cronStr=%s", the.CronStr) } // RegisterFun 注册定时器方法 func (the *MonitorHelper) registerFun(task func()) { entryID, err := the.Cron.AddFunc(the.CronStr, task) if err != nil { log.Printf("cron 定时任务[%v]添加异常:%s", entryID, err.Error()) } } func (the *MonitorHelper) monitorStart() { the.Cron.Start() }