mirror of
https://github.com/lzh-1625/go_process_manager.git
synced 2025-10-07 00:43:33 +08:00
初次提交
This commit is contained in:
35
service/push/push.go
Normal file
35
service/push/push.go
Normal file
@@ -0,0 +1,35 @@
|
||||
package push
|
||||
|
||||
import (
|
||||
"msm/dao"
|
||||
"strings"
|
||||
|
||||
"github.com/levigross/grequests"
|
||||
)
|
||||
|
||||
type pushService struct{}
|
||||
|
||||
var PushService = new(pushService)
|
||||
|
||||
func (p *pushService) Push(placeholders map[string]string) {
|
||||
pl := dao.PushDao.GetPushList()
|
||||
for _, v := range pl {
|
||||
if v.Enable {
|
||||
if v.Method == "GET" {
|
||||
grequests.Get(p.getReplaceMessage(placeholders, v.Url), nil)
|
||||
}
|
||||
if v.Method == "POST" {
|
||||
grequests.Post(v.Url, &grequests.RequestOptions{
|
||||
JSON: p.getReplaceMessage(placeholders, v.Body),
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (p *pushService) getReplaceMessage(placeholders map[string]string, message string) string {
|
||||
for k, v := range placeholders {
|
||||
message = strings.ReplaceAll(message, k, v)
|
||||
}
|
||||
return message
|
||||
}
|
Reference in New Issue
Block a user