Skip to content

Commit

Permalink
No extra code
Browse files Browse the repository at this point in the history
  • Loading branch information
Anton Telyshev committed Jan 27, 2020
1 parent acbd1ea commit 31aae23
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 8 deletions.
5 changes: 3 additions & 2 deletions internal/generator/constructors/form_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -36,7 +37,7 @@ func Make{{ .Name }}(c *gin.Context) (result {{ .Name }}, errors []FieldError) {
}
return values[0], true
}
{{ end }}
{{ end }}
{{- end }}
{{ range $, $field := .Fields }}
Expand Down
6 changes: 0 additions & 6 deletions internal/generator/constructors/form_data_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit 31aae23

Please sign in to comment.