You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by GitBox <gi...@apache.org> on 2019/10/24 14:33:28 UTC

[GitHub] [mynewt-newt] utzig commented on a change in pull request #344: mfg: Support the "extra_manifest" field per-target and per-raw

utzig commented on a change in pull request #344: mfg: Support the "extra_manifest" field per-target and per-raw
URL: https://github.com/apache/mynewt-newt/pull/344#discussion_r338609608
 
 

 ##########
 File path: newt/mfg/decode.go
 ##########
 @@ -110,6 +112,40 @@ func decodeBoolDflt(kv map[string]interface{}, key string,
 	}
 }
 
+func decodeExtra(kv map[string]interface{},
+	key string) (map[string]interface{}, error) {
+
+	extra := kv[key]
+	if extra == nil {
+		return nil, nil
+	}
+
+	if _, ok := extra.(map[interface{}]interface{}); !ok {
+		return nil, util.FmtNewtError(
+			"invalid \"%s\" field: must be a map", key)
+	}
+
+	// If `extra` contains any maps, they were unmarshalled as
+	// `map[interface{}]interface{}`.  These need to be converted to
+	// `map[string]interface{}` to be JSON compatible.
+	var fixMap func(m map[string]interface{})
+	fixMap = func(m map[string]interface{}) {
+		for k, v := range m {
+			if _, ok := v.(map[interface{}]interface{}); ok {
+				sm := cast.ToStringMap(v)
+				fixMap(sm)
+
+				m[k] = sm
 
 Review comment:
   When this adds a new `string` key from the cast, does the previous `interface{}` key remain in the map?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services