Skip to content

Commit

Permalink
Merge pull request #14 from Moranilt/feature/valid-multipart-types
Browse files Browse the repository at this point in the history
feat: add WeaklyTypedInput to mapstructure decoder
  • Loading branch information
Moranilt committed Mar 19, 2024
2 parents 6cc16d5 + 3486275 commit b711dd9
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion handler/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,18 @@ func (h *HandlerMaker[ReqT, RespT]) WithMultipart(maxMemory int64) *HandlerMaker
}
}

err = mapstructure.Decode(result, &h.requestBody)
cfg := &mapstructure.DecoderConfig{
WeaklyTypedInput: true,
Result: &h.requestBody,
}

decoder, err := mapstructure.NewDecoder(cfg)
if err != nil {
h.setError(ErrNotValidBodyFormat, err.Error())
return h
}

err = decoder.Decode(result)
if err != nil {
h.setError(ErrNotValidBodyFormat, err.Error())
return h
Expand Down

0 comments on commit b711dd9

Please sign in to comment.