Remove unused request functions

This commit is contained in:
Tulir Asokan 2023-07-17 16:57:28 +03:00
parent 13124562b7
commit 37a6c09dc3

View file

@ -3,42 +3,10 @@ package libgm
import ( import (
"bytes" "bytes"
"net/http" "net/http"
"reflect"
"go.mau.fi/mautrix-gmessages/libgm/util" "go.mau.fi/mautrix-gmessages/libgm/util"
) )
func (c *Client) PostRequest(url string, payload []byte, headers interface{}) (*http.Response, error) {
req, err := http.NewRequest("POST", url, bytes.NewReader(payload))
if err != nil {
return nil, err
}
reqHeaders := &http.Header{}
SetHeaders(reqHeaders, headers)
req.Header = *reqHeaders
res, reqErr := c.http.Do(req)
if reqErr != nil {
return res, reqErr
}
return res, nil
}
func (c *Client) GetRequest(url string, headers interface{}) (*http.Response, error) {
req, err := http.NewRequest("GET", url, nil)
if err != nil {
return nil, err
}
reqHeaders := &http.Header{}
SetHeaders(reqHeaders, headers)
req.Header = *reqHeaders
res, reqErr := c.http.Do(req)
if reqErr != nil {
return res, reqErr
}
return res, nil
}
func (c *Client) MakeRelayRequest(url string, body []byte) (*http.Response, error) { func (c *Client) MakeRelayRequest(url string, body []byte) (*http.Response, error) {
req, err := http.NewRequest("POST", url, bytes.NewReader(body)) req, err := http.NewRequest("POST", url, bytes.NewReader(body))
if err != nil { if err != nil {
@ -51,17 +19,3 @@ func (c *Client) MakeRelayRequest(url string, body []byte) (*http.Response, erro
} }
return res, nil return res, nil
} }
func SetHeaders(h *http.Header, headers interface{}) {
if headers == nil {
return
}
v := reflect.ValueOf(headers)
for i := 0; i < v.NumField(); i++ {
field := v.Type().Field(i)
value := v.Field(i).String()
if !v.Field(i).IsZero() {
h.Set(field.Tag.Get("header"), value)
}
}
}