-
-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: enable HTTP request/response logging in debug mode (#50)
- Add `debug` field to `Client` struct - Initialize `httpClient` with `debugTransport` if `debug` mode is enabled - Create `debug.go` to define `debugTransport` for logging HTTP requests and responses - Add `WithDebug` option to configure debug mode in `option.go` Signed-off-by: appleboy <[email protected]>
- Loading branch information
Showing
3 changed files
with
55 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package fcm | ||
|
||
import ( | ||
"log" | ||
"net/http" | ||
"net/http/httputil" | ||
) | ||
|
||
type debugTransport struct { | ||
t http.RoundTripper | ||
} | ||
|
||
func (d debugTransport) RoundTrip(req *http.Request) (*http.Response, error) { | ||
reqDump, err := httputil.DumpRequest(req, true) | ||
if err != nil { | ||
return nil, err | ||
} | ||
log.Printf("%s", reqDump) | ||
|
||
resp, err := d.t.RoundTrip(req) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
respDump, err := httputil.DumpResponse(resp, true) | ||
if err != nil { | ||
resp.Body.Close() | ||
return nil, err | ||
} | ||
log.Printf("%s", respDump) | ||
return resp, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters