diff options
author | Wim <wim@42.be> | 2019-06-16 23:33:25 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-06-16 23:33:25 +0200 |
commit | cb712ff37d3c20a21695e00c52fff213a6fd40b4 (patch) | |
tree | 0ba0ee4f55bf6ace2656562465cc82d807e741b9 /vendor/github.com/labstack/echo/v4/bind.go | |
parent | f4ae61044888f591830e6c1be9a2bdb14f88943e (diff) | |
download | matterbridge-msglm-cb712ff37d3c20a21695e00c52fff213a6fd40b4.tar.gz matterbridge-msglm-cb712ff37d3c20a21695e00c52fff213a6fd40b4.tar.bz2 matterbridge-msglm-cb712ff37d3c20a21695e00c52fff213a6fd40b4.zip |
Update vendor (#852)
Diffstat (limited to 'vendor/github.com/labstack/echo/v4/bind.go')
-rw-r--r-- | vendor/github.com/labstack/echo/v4/bind.go | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/vendor/github.com/labstack/echo/v4/bind.go b/vendor/github.com/labstack/echo/v4/bind.go index cb65ed2d..07d8034c 100644 --- a/vendor/github.com/labstack/echo/v4/bind.go +++ b/vendor/github.com/labstack/echo/v4/bind.go @@ -1,6 +1,7 @@ package echo import ( + "encoding" "encoding/json" "encoding/xml" "errors" @@ -21,6 +22,8 @@ type ( DefaultBinder struct{} // BindUnmarshaler is the interface used to wrap the UnmarshalParam method. + // Types that don't implement this, but do implement encoding.TextUnmarshaler + // will use that interface instead. BindUnmarshaler interface { // UnmarshalParam decodes and assigns a value from an form or query param. UnmarshalParam(param string) error @@ -211,12 +214,30 @@ func bindUnmarshaler(field reflect.Value) (BindUnmarshaler, bool) { return nil, false } +// textUnmarshaler attempts to unmarshal a reflect.Value into a TextUnmarshaler +func textUnmarshaler(field reflect.Value) (encoding.TextUnmarshaler, bool) { + ptr := reflect.New(field.Type()) + if ptr.CanInterface() { + iface := ptr.Interface() + if unmarshaler, ok := iface.(encoding.TextUnmarshaler); ok { + return unmarshaler, ok + } + } + return nil, false +} + func unmarshalFieldNonPtr(value string, field reflect.Value) (bool, error) { if unmarshaler, ok := bindUnmarshaler(field); ok { err := unmarshaler.UnmarshalParam(value) field.Set(reflect.ValueOf(unmarshaler).Elem()) return true, err } + if unmarshaler, ok := textUnmarshaler(field); ok { + err := unmarshaler.UnmarshalText([]byte(value)) + field.Set(reflect.ValueOf(unmarshaler).Elem()) + return true, err + } + return false, nil } |