Skip to content
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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion marshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Copy link
Contributor

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.

return nil
var err error
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternately, don't declare err here:

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
Copy link
Contributor

@seh seh Aug 22, 2016

Choose a reason for hiding this comment

The 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?

Copy link
Author

Choose a reason for hiding this comment

The 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

Copy link
Contributor

Choose a reason for hiding this comment

The 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.
Expand Down