-
Notifications
You must be signed in to change notification settings - Fork 53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unmarshal instance metadata JSON #40
base: master
Are you sure you want to change the base?
Changes from 1 commit
a5cca36
bb80962
cfebc47
a67a27c
558b027
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -106,7 +106,13 @@ func parsePort(s string) int { | |
func (i *InstanceMetadata) UnmarshalJSON(b []byte) error { | ||
i.Raw = b | ||
// TODO(cq) could actually parse Raw here, and in a parallel UnmarshalXML as well. | ||
return nil | ||
var err error | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Alternately, don't declare if err := json.Unmarshall(b, &m); err != nil {
return err
}
i.parsed = m
return nil One other idea: use a named return value. if err = json.Unmarshal(b, &m); err != nil {
i.parsed = m
}
return |
||
var m map[string]interface{} | ||
if err = json.Unmarshal(b, &m); err == nil { | ||
i.parsed = m | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should field "parsed" be exported as "Parsed"? We could rename it to something like "Fields" or "Map". If not, apart from round-tripping the parsed metadata, what's the good of parsing it if clients can't read it or write it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes,We should export field "parsed" to Parsed,I already do that in my code There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will you be including that exporting change in this patch series? |
||
return nil | ||
} | ||
return err | ||
} | ||
|
||
// MarshalJSON is a custom JSON marshaler for InstanceMetadata. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update the comment to note the only outstanding proposal: unmarshal the XML. You took care of the first proposal here.