code refactor

This commit is contained in:
Simon Ding
2024-08-02 10:08:26 +08:00
parent c28e16805e
commit c787d71fbd
12 changed files with 475 additions and 386 deletions

View File

@@ -2,8 +2,6 @@ package server
import (
"polaris/ent"
"polaris/log"
"polaris/pkg/notifier"
"strconv"
"github.com/gin-gonic/gin"
@@ -44,32 +42,3 @@ func (s *Server) AddNotificationClient(c *gin.Context) (interface{}, error) {
}
return nil, nil
}
func (s *Server) sendMsg(msg string) {
clients, err := s.db.GetAllNotificationClients2()
if err != nil {
log.Errorf("query notification clients: %v", err)
return
}
for _, cl := range clients {
if !cl.Enabled {
continue
}
handler, ok := notifier.Gethandler(cl.Service)
if !ok {
log.Errorf("no notification implementation of service %s", cl.Service)
continue
}
noCl, err := handler(cl.Settings)
if err != nil {
log.Errorf("handle setting for name %s error: %v", cl.Name, err)
continue
}
err = noCl.SendMsg(msg)
if err != nil {
log.Errorf("send message error: %v", err)
continue
}
log.Debugf("send message to %s success, msg is %s", cl.Name, msg)
}
}