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

fix: do not use a pointer receiver for Status.MarshalJSON #436

Merged
merged 1 commit into from
Sep 10, 2024
Merged
Changes from all commits
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
2 changes: 1 addition & 1 deletion pkg/types/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func (s *Status) Index() int {
return int(*s)
}

func (s *Status) MarshalJSON() ([]byte, error) {
func (s Status) MarshalJSON() ([]byte, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Now struct Status has methods on both value (UnmarshalJSON) and pointer (String, Index and UnmarshalJSON) receivers.

Should we change receivers for other functions too?

Copy link
Contributor

@DmitriyLewen DmitriyLewen Sep 10, 2024

Choose a reason for hiding this comment

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

But in this case we can't set Status to UnmarshalJSON, or am I wrong?

Copy link
Contributor

Choose a reason for hiding this comment

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

it seems it's a common practice to use value receiver for UnmarshalJSON and pointer for other methods:
https://github.com/CycloneDX/cyclonedx-go/blob/6f53207eded10e9e2a362772b253621840e7ad94/cyclonedx_json.go

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, MarshalJSON and UnmarshalJSON should be excluded from the linter rule.
https://youtrack.jetbrains.com/issue/GO-13587

return json.Marshal(s.String())
}

Expand Down