added send message function.

This commit is contained in:
5elenay
2021-08-21 00:22:45 +03:00
parent a77f3d097d
commit d025726680
5 changed files with 74 additions and 32 deletions

22
http.go
View File

@@ -4,43 +4,33 @@ import (
"bytes"
"io/ioutil"
"net/http"
"strings"
)
// Send http request
func (c *Client) Request(method, path, data string) ([]byte, error) {
var reqBody *bytes.Buffer
// Check method
if strings.EqualFold(method, "get") {
reqBody = bytes.NewBuffer([]byte(data))
} else {
reqBody = nil
}
func (c Client) Request(method, path string, data []byte) ([]byte, error) {
reqBody := bytes.NewBuffer(data)
// Prepare request
req, err := http.NewRequest(method, API_URL+path, reqBody)
if err != nil {
return []byte(""), err
return []byte{}, err
}
req.Header.Set("X-Bot-Token", c.Token)
req.Header.Set("Content-Type", "application/json")
client := &http.Client{}
// Send request
resp, err := client.Do(req)
resp, err := c.HTTP.Do(req)
if err != nil {
return []byte(""), err
return []byte{}, err
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return []byte(""), err
return []byte{}, err
}
return body, nil