-
Notifications
You must be signed in to change notification settings - Fork 244
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
Fix logentry.channel json marshaling/unmarshaling #264
Changes from 1 commit
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 |
---|---|---|
|
@@ -40,7 +40,7 @@ type CommonLogEntryField struct { | |
// LogEntry is a list of all of the events that happened to an incident. | ||
type LogEntry struct { | ||
CommonLogEntryField | ||
Incident Incident | ||
Incident Incident `json:"incident"` | ||
} | ||
|
||
// ListLogEntryResponse is the response data when calling the ListLogEntry API endpoint. | ||
|
@@ -115,8 +115,27 @@ func (c *Channel) UnmarshalJSON(b []byte) error { | |
ct, ok := raw["type"] | ||
if ok { | ||
c.Type = ct.(string) | ||
delete(raw, "type") | ||
c.Raw = raw | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// MarshalJSON Expands the LogEntry.Channel object to correctly marshal it back | ||
func (c *Channel) MarshalJSON() ([]byte, error) { | ||
raw := map[string]interface{}{} | ||
if c != nil && c.Type != "" { | ||
raw["type"] = c.Type | ||
for k, v := range c.Raw { | ||
raw[k] = v | ||
} | ||
} | ||
|
||
b, err := json.Marshal(raw) | ||
if err != nil { | ||
return nil, err | ||
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. I suspect 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. Nice catch. I'll fix it |
||
} | ||
|
||
return b, nil | ||
} |
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.
Sorry, I'm going to be a real pain in your rear here... For some reason it didn't dawn on me that removing this would also be a breaking change, and also make it not the raw object anymore. Would you have the spare moment to squash out this line? If not I can fix it after merging this PR.
Thank you so much for this contribution.
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.
Not a problem at all. I'll send update shortly