Client options (#53)

This commit is contained in:
Kirill
2023-12-11 21:30:36 +03:00
committed by GitHub
parent 1494ff5905
commit de08ee28c0
3 changed files with 83 additions and 7 deletions

View File

@@ -7,6 +7,7 @@ import (
"io/ioutil"
"net/http"
"net/http/httptest"
"net/url"
)
type HttpClient interface {
@@ -34,14 +35,17 @@ func NewMockClient(handler http.HandlerFunc) *Client {
}
}
func (c Client) newRequest(ctx context.Context, method string, url string, body interface{}) (*http.Request, error) {
func (c Client) newRequest(ctx context.Context, method string, uri string, body interface{}) (*http.Request, error) {
bodyJson, err := json.Marshal(body)
if err != nil {
return nil, err
}
url = c.baseUrl + url
req, err := http.NewRequestWithContext(ctx, method, url, bytes.NewBuffer(bodyJson))
uri, err = url.JoinPath(c.baseUrl, uri)
if err != nil {
return nil, err
}
req, err := http.NewRequestWithContext(ctx, method, uri, bytes.NewBuffer(bodyJson))
if err != nil {
return nil, err
}