Reimplement default values (#65)

This commit is contained in:
Kirill
2024-01-29 23:22:57 +03:00
committed by GitHub
parent 35832e6269
commit 2f94b8c774
9 changed files with 182 additions and 76 deletions

View File

@@ -8,6 +8,7 @@ import (
"net/http"
"net/http/httptest"
"net/url"
"reflect"
)
type HttpClient interface {
@@ -36,6 +37,14 @@ func NewMockClient(handler http.HandlerFunc) *Client {
}
func (c Client) newRequest(ctx context.Context, method string, uri string, body interface{}) (*http.Request, error) {
// Set default values for empty fields if `default` tag is present
// And body is not nil
if body != nil {
if err := getDefaultValues(reflect.ValueOf(body)); err != nil {
return nil, err
}
}
bodyJson, err := json.Marshal(body)
if err != nil {
return nil, err