Ai
64 Star 414 Fork 134

admpub/nging

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
alertTopic_ext.go 1.28 KB
一键复制 编辑 原始数据 按行查看 历史
admpub 提交于 2020-06-10 20:05 +08:00 . improved
package model
import (
"encoding/json"
"github.com/admpub/nging/application/dbschema"
"github.com/admpub/nging/application/model/alert"
alertRegistry "github.com/admpub/nging/application/registry/alert"
"github.com/webx-top/com"
"github.com/webx-top/echo"
"github.com/webx-top/echo/param"
)
type AlertTopicExt struct {
*dbschema.NgingAlertTopic
Recipient *dbschema.NgingAlertRecipient `db:"-,relation=id:recipient_id"`
Extra echo.H
}
func init() {
alertRegistry.SendTopic = func(ctx echo.Context, topic string, params param.Store) error {
return AlertSend(ctx, topic, params)
}
}
func AlertSend(ctx echo.Context, topic string, params param.Store) error {
m := NewAlertTopic(ctx)
return m.Send(topic, params)
}
func (a *AlertTopicExt) Parse() *AlertTopicExt {
if a.Extra != nil {
return a
}
a.Extra = echo.H{}
if a.Recipient == nil {
return a
}
if len(a.Recipient.Extra) > 0 {
json.Unmarshal(com.Str2bytes(a.Recipient.Extra), &a.Extra)
}
return a
}
func (a *AlertTopicExt) Send(params param.Store) (err error) {
if a.Recipient == nil || a.Recipient.Disabled == `Y` {
return
}
a.Parse()
return alertSend(a.Recipient, a.Extra, params)
}
func alertSend(a *dbschema.NgingAlertRecipient, extra echo.H, params param.Store) (err error) {
return alert.Send(a, extra, params)
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/admpub/nging.git
git@gitee.com:admpub/nging.git
admpub
nging
nging
v2.2.3

搜索帮助