Przeglądaj źródła

refactor rest code (#895)

Kevin Wan 3 lat temu
rodzic
commit
54d57c7d4b
2 zmienionych plików z 7 dodań i 5 usunięć
  1. 5 4
      core/mapping/unmarshaler.go
  2. 2 1
      rest/httpx/requests.go

+ 5 - 4
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)
 	}

+ 2 - 1
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.