1 Star 0 Fork 0

magicianlyx/GoLog

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
alarm.go 461 Bytes
一键复制 编辑 原始数据 按行查看 历史
lrf123456 提交于 2020-02-20 18:38 . -
package alarm
import "time"
type IAlarm interface {
Send(msg string) error
GetLastSendTime() time.Time
}
type Alarm struct {
alarms []IAlarm
sep time.Duration
}
func NewAlarm(alarms []IAlarm, sep time.Duration) *Alarm {
return &Alarm{alarms: alarms, sep: sep}
}
func (l *Alarm) Send(msg string) {
alarms := l.alarms
now := time.Now()
for _, alarm := range alarms {
if now.Sub(alarm.GetLastSendTime()) > l.sep {
_ = alarm.Send(msg)
}
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/magicianlyx/GoLog.git
git@gitee.com:magicianlyx/GoLog.git
magicianlyx
GoLog
GoLog
20c45f9b998d

搜索帮助

23e8dbc6 1850385 7e0993f3 1850385