您的位置:首页 > 编程语言 > Go语言

Go-实现程序零点定时启动

2017-12-03 16:33 375 查看
需要实现定时启动,这里采用的是定时器的方式进行,当然可以使用ticket,代码如下:

package main

import(
"time"
)

func WriteWork(writereload func()) {
go func() {
writereload()
for {
now := time.Now()
// 下一个零点
next := now.Add(time.Hour * 24)
next = time.Date(next.Year(), next.Month(), next.Day(), 0, 0, 0, 0, next.Location())
t := time.NewTimer(next.Sub(now))
defer LogFile.Close()
writereload()
<-t.C
}
}()
}

func WriteReload(){
//init work
fmt.Println("start...")
}

func main(){
WriteWork(WriteReload)
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: