-
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
Open
tianxiaoliang
wants to merge
5
commits into
hudl:master
Choose a base branch
from
tianxiaoliang:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
a5cca36
Unmarshal instance metadata JSON
tianxiaoliang bb80962
Update marshal.go
tianxiaoliang cfebc47
Update marshal.go
tianxiaoliang a67a27c
Ummarshal Metadata json and Export parsed metadata
558b027
Ummarshal Metadata json and Export parsed metadata
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,23 +23,23 @@ func (a *Application) ParseAllMetadata() error { | |
|
||
// SetMetadataString for a given instance before register | ||
func (ins *Instance) SetMetadataString(key, value string) { | ||
if ins.Metadata.parsed == nil { | ||
ins.Metadata.parsed = map[string]interface{}{} | ||
if ins.Metadata.Parsed == nil { | ||
ins.Metadata.Parsed = map[string]interface{}{} | ||
} | ||
ins.Metadata.parsed[key] = value | ||
ins.Metadata.Parsed[key] = value | ||
} | ||
|
||
func (im *InstanceMetadata) parse() error { | ||
if len(im.Raw) == 0 { | ||
im.parsed = make(map[string]interface{}) | ||
im.Parsed = make(map[string]interface{}) | ||
log.Debug("len(Metadata)==0. Quitting parsing.") | ||
return nil | ||
} | ||
metadataLog.Debugf("InstanceMetadata.parse: %s", im.Raw) | ||
|
||
if len(im.Raw) > 0 && im.Raw[0] == '{' { | ||
// JSON | ||
err := json.Unmarshal(im.Raw, &im.parsed) | ||
err := json.Unmarshal(im.Raw, &im.Parsed) | ||
if err != nil { | ||
log.Errorf("Error unmarshalling: %s", err.Error()) | ||
return fmt.Errorf("error unmarshalling: %s", err.Error()) | ||
|
@@ -52,22 +52,22 @@ func (im *InstanceMetadata) parse() error { | |
log.Errorf("Error unmarshalling: %s", err.Error()) | ||
return fmt.Errorf("error unmarshalling: %s", err.Error()) | ||
} | ||
im.parsed = parsedDoc["d"].(map[string]interface{}) | ||
im.Parsed = parsedDoc["d"].(map[string]interface{}) | ||
} | ||
return nil | ||
} | ||
|
||
// GetMap returns a map of the metadata parameters for this instance | ||
func (im *InstanceMetadata) GetMap() map[string]interface{} { | ||
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. Now that the underlying field is exported, this method isn't necessary, but I doubt we can get away with removing it, as that would break existing callers. |
||
return im.parsed | ||
return im.Parsed | ||
} | ||
|
||
func (im *InstanceMetadata) getItem(key string) (interface{}, bool, error) { | ||
err := im.parse() | ||
if err != nil { | ||
return "", false, fmt.Errorf("parsing error: %s", err.Error()) | ||
} | ||
val, present := im.parsed[key] | ||
val, present := im.Parsed[key] | ||
return val, present, nil | ||
} | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Given that we can set entries in this field, "Parsed" doesn't match its use. "Parsed" implies that we only receive these values.
Again, consider renaming it to "Map", "Fields", "Values", or something similar.