mirror of
https://github.com/lzh-1625/go_process_manager.git
synced 2025-09-26 20:11:20 +08:00
36 lines
730 B
Go
36 lines
730 B
Go
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
|
|
}
|