From 54d57c7d4b85be3f6cbcbe040215e912520e47a9 Mon Sep 17 00:00:00 2001 From: Kevin Wan Date: Tue, 10 Aug 2021 17:59:33 +0800 Subject: [PATCH] refactor rest code (#895) --- core/mapping/unmarshaler.go | 9 +++++---- rest/httpx/requests.go | 3 ++- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/core/mapping/unmarshaler.go b/core/mapping/unmarshaler.go index 4069492b..b1ea2dbb 100644 --- a/core/mapping/unmarshaler.go +++ b/core/mapping/unmarshaler.go @@ -322,12 +322,13 @@ func (u *Unmarshaler) processNamedField(field reflect.StructField, value reflect if err != nil { return err } - k := key + + fullName = join(fullName, key) + canonicalKey := key if u.opts.canonicalKey != nil { - k = u.opts.canonicalKey(key) + canonicalKey = u.opts.canonicalKey(key) } - fullName = join(fullName, key) - mapValue, hasValue := getValue(m, k) + mapValue, hasValue := getValue(m, canonicalKey) if hasValue { return u.processNamedFieldWithValue(field, value, mapValue, key, opts, fullName) } diff --git a/rest/httpx/requests.go b/rest/httpx/requests.go index c6469bee..61e4a67e 100644 --- a/rest/httpx/requests.go +++ b/rest/httpx/requests.go @@ -24,7 +24,8 @@ const ( var ( formUnmarshaler = mapping.NewUnmarshaler(formKey, mapping.WithStringValues()) pathUnmarshaler = mapping.NewUnmarshaler(pathKey, mapping.WithStringValues()) - headerUnmarshaler = mapping.NewUnmarshaler(headerKey, mapping.WithStringValues(), mapping.WithCanonicalKeyFunc(textproto.CanonicalMIMEHeaderKey)) + headerUnmarshaler = mapping.NewUnmarshaler(headerKey, mapping.WithStringValues(), + mapping.WithCanonicalKeyFunc(textproto.CanonicalMIMEHeaderKey)) ) // Parse parses the request.