33 lines
605 B
Go
33 lines
605 B
Go
package main
|
|
|
|
import (
|
|
"bytes"
|
|
"encoding/json"
|
|
"io/ioutil"
|
|
"net/http"
|
|
)
|
|
|
|
type message struct {
|
|
Text string `form:"text" json:"text"`
|
|
Filename string `form:"filename" json:"filename"`
|
|
Key string `form:"key" json:"key"`
|
|
Info string `form:"info" json:"info"`
|
|
}
|
|
|
|
func requestDingApi(url string, msg message) error {
|
|
b, err := json.Marshal(msg)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
resp, err := http.Post(url, "application/json", bytes.NewBuffer(b))
|
|
if err != nil {
|
|
return err
|
|
}
|
|
defer resp.Body.Close()
|
|
_, err = ioutil.ReadAll(resp.Body)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return err
|
|
}
|