-
Notifications
You must be signed in to change notification settings - Fork 51
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
refactor: Change handler functions implementation and response formatting #498
refactor: Change handler functions implementation and response formatting #498
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.
Looks good! Code is much nicer IMO - just got the one comment on one func which I think could be made nicer still. Would also suggest commiting with a lightly more specific message than the current PR title as it sounds a be vague to me atm (maybe something like 'Refactor handler response formatting', and then just note the API v change in the commit body?).
Approved assuming you respond sensibly to my one comment pre-merge :)
@AndrewSisley let me know if you like the changed PR title better |
Is good - cheers Fred! |
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.
Approved conditional on typo and ioutil
issue being fixed.
rw, | ||
dataResponse{map[string]interface{}{"result": "success"}}, | ||
http.StatusBadRequest, | ||
) | ||
} | ||
|
||
func getBlockHandler(rw http.ResponseWriter, req *http.Request) { |
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.
suggestion(non-blocking): there could be tests for the following in getBlockHandler
(lack of them can be seen via code coverage):
dag.DecodeProtobuf(block.RawData())
failingbuf, err := nd.MarshalJSON()
failingdelta, err := reg.DeltaDecode(nd)
failingdata, err := delta.Marshal()
failing
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.
If you can give me an example of a request that would make them fail individually I would gladly add it. They are the only 4 untested blocks in the package because I couldn't find a way to make them fail.
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, my comment was not thought out. I don't have such an example.
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.
Beautiful Work! Super happy with the testing, as the coverage drop that we had in 593214a comes back up 💪 significantly in this PR.
Mr. @orpheuslummis beat me to my concerns with ioutil
stuff. But approving for now assuming that will be fixed 😄
8bab889
to
418cb1a
Compare
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.
LGTM, minor thought added.
nitpick: Technically this PR covers 3 different bug
, feature
, and refactor
issues making it somewhat difficult to accurately assign a PR prefix, between the three. At the moment this has a refactor
prefix, which is prob the best since that is the most notable section of the change, and the others are smaller.
Just has the negative consequence that when we generate the changelog the bugfix and feature won't be in the list explicitly.
// Odd arguments are the keys and must be strings otherwise they are ignored. | ||
// Even arguments are the values associated with the previous key. | ||
// Odd arguments are also ignored if there are no following arguments. | ||
func simpleDataResponse(args ...interface{}) dataResponse { |
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.
thought: Since this is an internal func, im not too worried about it, but just wondering in case a dev shoots themselves in the foot and have an un-even number of func args so the keys/values don't line up.
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.
If it's an odd number of arguments, the last one is discarded as the function documentation says. They will then notice that some information is missing in the payload which will prompt them to look at the data sent to the sendJSON function.
7722344
to
e04a008
Compare
That's usually a pretty common situation with refactors no? Otherwise it would have made for pretty incomplete dependant PRs. |
e04a008
to
ae3eb52
Compare
Codecov Report
@@ Coverage Diff @@
## develop #498 +/- ##
===========================================
+ Coverage 52.55% 54.10% +1.54%
===========================================
Files 97 97
Lines 13170 13099 -71
===========================================
+ Hits 6922 7087 +165
+ Misses 5574 5337 -237
- Partials 674 675 +1
|
Its common enough to have a |
Unrelated, as in not dependant, not unrelated to the section of changes.** |
I really dont want to discourage refactoring in anyway - I think ideally yes it would be nice if they were all split out into different PRs, but that is not always practical, and if we start asking people to do this it may (slightly) discourage refactoring leading to a slightly less nice code base |
I'm curious as to which feature you are talking about. |
This is only in reference to the 3 linked issues. #384 Obviously the refactor here spans a lot of different aspects/potential bug fixes/features just to resolve #384. In addition to the various changes needed for 384. This PR also implements the I'm all for adding whatever is needed to implement a given task, and resolving multiple tickets within a single PR, just a nitpick from the perspective of the changelog only for the independant change of #494. |
Exactly, due to the size (1 liner) of the change, its completely reasonable to throw it in here :). |
…ting (sourcenetwork#498) RELEVANT ISSUE(S) Resolves sourcenetwork#384 Resolves sourcenetwork#458 Resolves sourcenetwork#494 DESCRIPTION After the HTTP API refactor, we now focus on the refactoring of the handler functions themselves ensuring common response formats for both successful and error responses across the API. This PR also changes the API version number to v0 from v1 to show "unstable" status and responds with the appropriate content-type with JSON payloads.
RELEVANT ISSUE(S)
Resolves #384
Resolves #458
Resolves #494
DESCRIPTION
After the HTTP API refactor, we now focus on the refactoring of the handler functions themselves ensuring common response formats for both successful and error responses across the API.
This PR also changes the API version number to v0 from v1 to show "unstable" status and responds with the appropriate content-type with JSON payloads.
HOW HAS THIS BEEN TESTED?
These changes have been unit tested.
CHECKLIST:
ENVIRONMENT / OS THIS WAS TESTED ON?
Please specify which of the following was this tested on (remove or add your own):