-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
jsonrpc add id from request to response #742
Conversation
Thanks for the PR. Can you please add a unit test for the correct behavior? |
Not sure why the tests failed (timeout) |
} | ||
} | ||
|
||
func TestCanMarshalNullID(t *testing.T) { |
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.
why a separate test for null? wouldn't this fit the TestCanMarshalID test (adding a case for it)
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.
test updated
@peterbourgon can you review? i’ll be offline the next 2 weeks. |
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.
With that one comment addressed, I'm +1
} else { | ||
return json.Marshal(id.stringValue) | ||
} | ||
} |
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.
My sense is this would be better expressed without the short-circuit logic, as
switch {
case id.intError == nil && id.floatError != nil:
return json.Marshal(id.intValue)
case id.intError != nil && id.floatError == nil:
return json.Marshal(id.floatValue)
default:
return json.Marshal(id.stringValue)
}
What do you think?
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.
I dont think so, intError and floatError can both be 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.
Yes, if intErr == nil and floatErr == nil, the final default case is triggered.
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.
For integer value, intErr and floatErr are nil and the default case will return empty string.
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.
Ah, OK, I understand. Then the original implementation is best.
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.
Awesome!
Thank you! |
According to https://www.jsonrpc.org/specification:
This pull request add req.ID to response object.