pusher/pushers/anPush.go
timerzz 4ec0cd1564
Some checks failed
Build image / build (push) Failing after 4m48s
feat 测试
2024-05-20 17:57:25 +08:00

36 lines
864 B
Go

package pushers
import (
"context"
"fmt"
"gitea.timerzz.com/kedaya_haitao/pusher/kitex_gen/config"
"github.com/go-resty/resty/v2"
"strings"
)
type AnPush struct {
opt *config.AnPush
client *resty.Client
}
func NewAnPush(opt *config.AnPush) *AnPush {
return &AnPush{
opt: opt,
client: resty.New().SetHeader("Content-Type", "application/x-www-form-urlencoded"),
}
}
type msgResponse struct {
Errcode int `json:"errcode"`
Errmsg string `json:"errmsg"`
Msgid uint64 `json:"msgid"`
}
func (a *AnPush) Push(ctx context.Context, title, content string) error {
r := a.client.R().SetBody(strings.NewReader(fmt.Sprintf("title=%s&content=%s&channel=%s", title, content, a.opt.Channel))).SetContext(ctx)
var result msgResponse
r.SetResult(&result)
_, err := r.Post(fmt.Sprintf("https://api.anpush.com/push/%s", a.opt.Token))
return err
}