-
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
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
Add support for dumping request and response in Go generated clients #4566
Conversation
The following change adds a new configuration setting, which controls whether clients want to dump the HTTP request and response. Useful when debugging API calls and clients.
@dnaeon thanks for the PR. What about using a logger (e.g. https://github.com/google/logger) instead? |
Hey @wing328, I've tested it with a logger first, but the results weren't pretty, that's why I've left it using just |
This should really be done with middleware, not in the client directly. Is there a reason it cant be? |
Can you please elaborate? |
FYI. For other clients (e.g. Ruby), we also use a logger for debugging purposes. |
@wing328 Here's one example. https://play.golang.org/p/o5LE9R5iCpj Basically the timestamp of the logger is attached to just the first line of the output, which makes it less pretty, IMO. Also, I found
@antihax That should work I guess. Can you point me to an example middleware I can lookup? Thanks! |
Here is an example of two chained middleware for the API client. Here are the implementations: You would create another of these that would dump the request and response. In the case here you would do something like this:
|
What about putting a "\n" at the beginning of the log? |
@antihax Thanks, that would work.
@antihax, @wing328 I'll leave it to you whether it's worth merging this PR considering that we can have the same thing done with either a middleware or custom roundtripper. |
@dnaeon the debug flag in other clients can be used not only for dumping request/response but also other troubleshooting (e.g. object serialization, etc). so if you're using a logger with the debug flag, I'll be happy to merge this into master. |
@wing328, I can take care of updating the PR. Which logger you'd prefer to have as part of the implementation? https://github.com/google/logger or the builtin |
Please start with the built-in one. Thanks
在 2019年11月23日週六 下午3:49,Marin Atanasov Nikolov <notifications@github.com> 寫道:
… @dnaeon <https://github.com/dnaeon> the debug flag in other clients can
be used not only for dumping request/response but also other
troubleshooting (e.g. object serialization, etc).
so if you're using a logger with the debug flag, I'll be happy to merge
this into master.
@wing328 <https://github.com/wing328>, I can take care of updating the PR.
Which logger you'd prefer to have as part of the implementation?
https://github.com/google/logger or the builtin log.Logger?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#4566?email_source=notifications&email_token=AAHEC5GYHQWUFJ2GI7EZJJLQVDOBHA5CNFSM4JQAIXC2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEE7P24I#issuecomment-557776241>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAHEC5E7Y3XUXR34ZKGHFCDQVDOBHANCNFSM4JQAIXCQ>
.
|
@wing328 just pushed a new commit which uses |
@dnaeon thanks for the PR, which looks good to me. |
@dnaeon when you've time, I wonder if you can file the same PR for |
The following change adds a new configuration setting, which
controls whether clients want to dump the HTTP request and response.
Useful when debugging API calls and clients.
PR checklist
./bin/
(or Windows batch scripts under.\bin\windows
) to update Petstore samples related to your fix. This is important, as CI jobs will verify all generator outputs of your HEAD commit, and these must match the expectations made by your contribution. You only need to run./bin/{LANG}-petstore.sh
,./bin/openapi3/{LANG}-petstore.sh
if updating the code or mustache templates for a language ({LANG}
) (e.g. php, ruby, python, etc).master
,4.3.x
,5.0.x
. Default:master
.