Fix empty body (#81)

This commit is contained in:
Kirill
2024-04-20 18:55:49 +03:00
committed by GitHub
parent 8a6ca3b2eb
commit 6cf4ae89e3

View File

@@ -37,18 +37,21 @@ func NewMockClient(handler http.HandlerFunc) *Client {
} }
func (c Client) newRequest(ctx context.Context, method string, uri string, body interface{}) (*http.Request, error) { func (c Client) newRequest(ctx context.Context, method string, uri string, body interface{}) (*http.Request, error) {
var err error
var bodyJson []byte
// Set default values for empty fields if `default` tag is present // Set default values for empty fields if `default` tag is present
// And body is not nil // And body is not nil
if body != nil { if body != nil {
if err := getDefaultValues(reflect.ValueOf(body)); err != nil { if err := getDefaultValues(reflect.ValueOf(body)); err != nil {
return nil, err return nil, err
} }
}
bodyJson, err := json.Marshal(body) bodyJson, err = json.Marshal(body)
if err != nil { if err != nil {
return nil, err return nil, err
} }
}
uri, err = url.JoinPath(c.baseUrl, uri) uri, err = url.JoinPath(c.baseUrl, uri)
if err != nil { if err != nil {