Fix empty body (#81)
This commit is contained in:
@@ -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 {
|
||||||
|
|||||||
Reference in New Issue
Block a user