feat: add custom webhook message

This commit is contained in:
engigu
2024-01-07 00:25:35 +08:00
parent e4a1b16e78
commit cf77fac836
18 changed files with 180 additions and 22 deletions
+31
View File
@@ -0,0 +1,31 @@
package message
import (
"bytes"
"io"
"net/http"
)
type CustomWebhook struct {
Webhook string
Body string
}
func (cw *CustomWebhook) Request(url string, msg string) ([]byte, error) {
resp, err := http.Post(url, "application/json", bytes.NewBuffer([]byte(msg)))
if err != nil {
return nil, err
}
defer func(Body io.ReadCloser) {
err := Body.Close()
if err != nil {
}
}(resp.Body)
body, err := io.ReadAll(resp.Body)
if err != nil {
return nil, err
}
return body, err
}
+6 -1
View File
@@ -33,7 +33,12 @@ func (t *Dtalk) Request(msg interface{}) ([]byte, error) {
return nil, err
}
defer resp.Body.Close()
defer func(Body io.ReadCloser) {
err := Body.Close()
if err != nil {
}
}(resp.Body)
body, err := io.ReadAll(resp.Body)
if err != nil {
return nil, err