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

feat: add NewJsonResponseOrPanic function to simplify calls with ResponderFromMultipleResponses #151

Merged
merged 1 commit into from Apr 18, 2024

Conversation

kilianpaquier
Copy link
Contributor

@kilianpaquier kilianpaquier commented Apr 13, 2024

Simplify calls to ResponderFromMultipleResponses for JSON body responses with NewJsonResponseOrPanic.

Just as the same as NewJsonResponderOrPanic and NewJsonResponder, it's an addition to simplify some calls and avoid local variables with error handling.

@kilianpaquier kilianpaquier force-pushed the dev/kpaquier/jsonresponse-panic branch from cff7f0c to ab25f47 Compare April 13, 2024 15:12
Copy link
Collaborator

@maxatome maxatome left a comment

Choose a reason for hiding this comment

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

Thanks for your PR. See my comments to go further.

Just as a note did you know that you can chain Responder using Then method? It appeared after ResponderFromMultipleResponses implementation. Using it you can do:

responder := httpmock.NewJsonResponderOrPanic(200, x).
  Then(httpmock.NewJsonResponderOrPanic(200, y)).
  Then(httpmock.NewJsonResponderOrPanic(200, z))

response.go Outdated Show resolved Hide resolved
response.go Outdated Show resolved Hide resolved
response.go Outdated Show resolved Hide resolved
response.go Outdated Show resolved Hide resolved
response.go Outdated Show resolved Hide resolved
@maxatome
Copy link
Collaborator

Could you please also change the commit message to:

feat: add NewJsonResponseOrPanic function

@kilianpaquier
Copy link
Contributor Author

kilianpaquier commented Apr 16, 2024

Thanks for your PR. See my comments to go further.

Just as a note did you know that you can chain Responder using Then method? It appeared after ResponderFromMultipleResponses implementation. Using it you can do:

responder := httpmock.NewJsonResponderOrPanic(200, x).

  Then(httpmock.NewJsonResponderOrPanic(200, y)).

  Then(httpmock.NewJsonResponderOrPanic(200, z))

Hi, yes I did see this builder function. We've been using it for the last two days, it's great too !

But I still think that NewJsonResponseOrPanic could be a useful addition, what do you think ?

@kilianpaquier
Copy link
Contributor Author

Could you please also change the commit message to:


feat: add NewJsonResponseOrPanic function

Will do !

@kilianpaquier kilianpaquier force-pushed the dev/kpaquier/jsonresponse-panic branch from ab25f47 to 80b8de4 Compare April 17, 2024 16:24
response_test.go Outdated Show resolved Hide resolved
response_test.go Outdated Show resolved Hide resolved
response.go Outdated Show resolved Hide resolved
@kilianpaquier kilianpaquier force-pushed the dev/kpaquier/jsonresponse-panic branch from 80b8de4 to 6eb2746 Compare April 17, 2024 17:32
@maxatome maxatome merged commit d95b1ca into jarcoal:v1 Apr 18, 2024
12 checks passed
@kilianpaquier kilianpaquier deleted the dev/kpaquier/jsonresponse-panic branch April 18, 2024 18:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants