From 31aae23592741039b913b08b4fdd7fea1fc0c60e Mon Sep 17 00:00:00 2001 From: Anton Telyshev Date: Mon, 27 Jan 2020 16:22:42 +0300 Subject: [PATCH] No extra code --- internal/generator/constructors/form_data.go | 5 +++-- internal/generator/constructors/form_data_test.go | 6 ------ 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/internal/generator/constructors/form_data.go b/internal/generator/constructors/form_data.go index 8067987..6610e79 100644 --- a/internal/generator/constructors/form_data.go +++ b/internal/generator/constructors/form_data.go @@ -20,12 +20,13 @@ func Make{{ .Name }}(c *gin.Context) (result {{ .Name }}, errors []FieldError) { {{ end }} {{- with .Fields }} + {{ if $.HasNoFileFields }} form, err := c.MultipartForm() if err != nil { errors = append(errors, NewFieldError(InFormData, "", "can't parse multipart form", err)) return } - {{ if $.HasNoFileFields }} + getFormValue := func(param string) (string, bool) { values, ok := form.Value[param] if !ok { @@ -36,7 +37,7 @@ func Make{{ .Name }}(c *gin.Context) (result {{ .Name }}, errors []FieldError) { } return values[0], true } - {{ end }} + {{ end }} {{- end }} {{ range $, $field := .Fields }} diff --git a/internal/generator/constructors/form_data_test.go b/internal/generator/constructors/form_data_test.go index 04e11c3..d5ed081 100644 --- a/internal/generator/constructors/form_data_test.go +++ b/internal/generator/constructors/form_data_test.go @@ -93,12 +93,6 @@ func TestMakeFormDataConstructorForOneFileField(t *testing.T) { func MakeUploadDocumentRequestBodyForm(c *gin.Context) (result UploadDocumentRequestBodyForm, errors []FieldError) { var err error - form, err := c.MultipartForm() - if err != nil { - errors = append(errors, NewFieldError(InFormData, "", "can't parse multipart form", err)) - return - } - result.Document, err = c.FormFile("document") if err != nil { errors = append(errors, NewFieldError(InFormData, "document", "can't extract file from form-data", err))