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 }