labstack / echo

High performance, minimalist Go web framework
https://echo.labstack.com
MIT License
29.94k stars 2.23k forks source link

Feature Request: Bind request's body multiple times #2641

Open samanebi opened 5 months ago

samanebi commented 5 months ago

I was struggling with Echo lately to be able to Bind a single request's body multiple times. But because of JSON decode this is not possible. I managed to solve my problem with writing a new Binder that is 90% equal to the DefaultBinder. I was wondering can we actually incorporate such feature inside Echo to avoid writing very similar code to address this matter?

To address this I was thinking about having an BindConfig struct inside DefaultBinder that has a boolean flag to enable or disable shadow read. So by enabling that we cache the decoded body inside context as a map and do the binding on that if it is present. This can not affect DefaultBinder's Bind function very much and the code change on it would be not much. But many guys like me would not be forced to write new Binder very similar to DefaultBinder.

I wanted to report this to see if this is possible or not. If it is possible i would be happy to contribute