-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Conversation
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.
Elena, I reckon this needs a test that makes sure it will decode old serialisations of release metadata -- even if it's just to prevent regressions. I've elaborated in a comment.
// ReleaseEventMetadata is the metadata for when service(s) are released | ||
type ReleaseEventMetadata struct { | ||
ReleaseEventCommon | ||
Spec update.ReleaseSpec `json:"spec"` | ||
Cause update.Cause `json:"cause"` | ||
Spec ReleaseSpec `json:"spec"` |
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
Right, but if I use embedded structs there is another issue here:
So now I tend to use a separate type for
|
Argh, I knew there was a catch. How about something like
EDIT: |
Not sure what it means:
but if I marshal a struct with named fields:
and then try to unmarshal it, I have |
For posterity: the purpose of the type alias is to create a type that has the same fields (and can therefore be unmarshalled into) but not the |
7337c9a
to
29845de
Compare
@squaremo Added UnmarshalJSON method, PTAL. |
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.
There's a bit of extra decoding which I don't think is necessary (see comments). Also, can you make sure you're using the most recent dep
(v0.5.0); I wouldn't expect any changes to Gopkg.lock (and those that are there look like formatting/metadata changes).
event/event.go
Outdated
func (s *ReleaseSpec) UnmarshalJSON(b []byte) error { | ||
type T ReleaseSpec | ||
t := (*T)(s) | ||
if err := json.Unmarshal(b, &t); err != 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.
t
is already a pointer *T
, so you don't need to pass its address.
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.
Fixed.
event/event.go
Outdated
|
||
case ReleaseImageSpecType, ReleaseContainersSpecType: | ||
r := (*T)(s) | ||
if err := json.Unmarshal(b, &r); err != 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.
r
is already a pointer; but moreover, this decoding has already been done, in line 264. I think this case is a no-op -- all the fields will have been decoded. (Is there a test that doesn't pass unless this line is present?)
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.
Fixed.
29845de
to
511f381
Compare
For ReleaseEventMetadata use spec with both types: ReleaseImageSpec and ReleaseContainersSpec Need this to fix weaveworks/service#2277
511f381
to
78030d9
Compare
Need this for: - #2277 - fluxcd/flux#1472
Need this for: - #2277 - fluxcd/flux#1472
Need this for: - #2277 - fluxcd/flux#1472
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.
Looks good, thanks Elena!
78030d9
to
641d52d
Compare
Need this for: - #2277 - fluxcd/flux#1472
For
ReleaseEventMetadata
use spec with both types:ReleaseImageSpec
andReleaseContainersSpec
.Need this for weaveworks/service#2277