This commit is contained in:
xxj
2024-03-01 17:20:59 +08:00
parent 8a00588372
commit 6114116d01
2 changed files with 14 additions and 7 deletions

View File

@@ -9,17 +9,17 @@ var _isDev = true
var service = "service" var service = "service"
var fileHost = "file" var fileHost = "file"
//是否开发模式 // 是否开发模式
func OnSetDev(isDev bool) { func OnSetDev(isDev bool) {
_isDev = isDev _isDev = isDev
} }
//IsDev ... 是否是开发版本 // IsDev ... 是否是开发版本
func IsDev() bool { func IsDev() bool {
return _isDev return _isDev
} }
//判断是否在测试环境下使用 // 判断是否在测试环境下使用
func IsRunTesting() bool { func IsRunTesting() bool {
if len(os.Args) > 1 { if len(os.Args) > 1 {
return strings.HasPrefix(os.Args[1], "-test") return strings.HasPrefix(os.Args[1], "-test")
@@ -27,22 +27,22 @@ func IsRunTesting() bool {
return false return false
} }
//设置服务名 // 设置服务名
func SetService(s string) { func SetService(s string) {
service = s service = s
} }
//获取服务名 // 获取服务名
func GetService() string { func GetService() string {
return service return service
} }
//设置服务名 // 设置服务名
func SetFileHost(s string) { func SetFileHost(s string) {
fileHost = s fileHost = s
} }
//获取文件host // 获取文件host
func GetFileHost() string { func GetFileHost() string {
return fileHost return fileHost
} }

View File

@@ -57,6 +57,13 @@ callback : 时间回调
*/ */
func OnPeDay(hour, min, sec int, callback func()) { func OnPeDay(hour, min, sec int, callback func()) {
go func() { go func() {
defer func() {
defer func() {
if err := recover(); err != nil {
mylog.Error("recover OnPeDay", err)
}
}()
}()
next := tools.GetDay0(time.Now().Unix()) next := tools.GetDay0(time.Now().Unix())
for { for {
next = time.Date(next.Year(), next.Month(), next.Day(), hour, min, sec, 0, next.Location()) next = time.Date(next.Year(), next.Month(), next.Day(), hour, min, sec, 0, next.Location())