initial commit
This commit is contained in:
commit
313bd35b23
8 changed files with 591 additions and 0 deletions
34
http.go
Normal file
34
http.go
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
package discord
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type Identifiable interface {
|
||||
BucketID() string
|
||||
}
|
||||
|
||||
func requestWithToken(
|
||||
token string,
|
||||
client *http.Client,
|
||||
method, url string,
|
||||
body any,
|
||||
) (*http.Response, error) {
|
||||
buf := &bytes.Buffer{}
|
||||
err := json.NewEncoder(buf).Encode(body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
req, err := http.NewRequest(method, url, buf)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
req.Header.Set("Authorization", "Bot "+token)
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
|
||||
return http.DefaultClient.Do(req)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue