echo icon indicating copy to clipboard operation
echo copied to clipboard

bind.go: add BindHeaders() to Bind()

Open chiyutianyi opened this issue 3 years ago • 7 comments

Headers are supported in Bind() and we can find the following in the documentation[1]:

Echo provides the following methods to bind data from different
sources to Go Structs using the Context#Bind(i interface{}) method:
- URL Path parameter
- URL Query parameter
- Request body
- Header
  1. https://echo.labstack.com/guide/binding/#bind-using-struct-tags

chiyutianyi avatar Sep 01 '22 14:09 chiyutianyi

There was a reason why header binding was not added to Bind method. See https://github.com/labstack/echo/pull/1866#issue-877401536

aldas avatar Sep 01 '22 15:09 aldas

There was a reason why header binding was not added to Bind method. See #1866 (comment)

Hmm, so should we revise the documentation to keep it the same with the implementation ?

chiyutianyi avatar Sep 02 '22 01:09 chiyutianyi

There was a reason why header binding was not added to Bind method. See #1866 (comment)

Hmm, so should we revise the documentation to keep it the same with the implementation ?

@chiyutianyi The section you are referring to is an introduction to the topic, which is then detailed later. But improving the docs is of course great! You can add a PR for the docs in the https://github.com/labstack/echox project

lammel avatar Nov 30 '22 13:11 lammel

@lammel @chiyutianyi -- Can we change this PR to expose BindHeaders() on echo.Context such that I can do: c.BindHeaders(params) instead of: (&echo.DefaultBinder{}).BindHeaders(*c, params)

Thanks!

derekm avatar Oct 12 '23 16:10 derekm

@derekm we can not change context interface by adding new public method as it would be API breaking change.

aldas avatar Oct 12 '23 16:10 aldas

@aldas -- Ahh, right. No default implementations in Go? At least generics are improving! ;) I do hide the ugly code under some reasonable abstractions. Thanks!

derekm avatar Oct 12 '23 16:10 derekm

we are using semantic versioning and adding new method to interface would be breaking (backwards incompatible) change and would require bumping major version of library to v5. We do not want to do that - not yet.

aldas avatar Oct 12 '23 16:10 aldas