Fix debug (#545)

As title.

Reviewed-on: https://gitea.com/gitea/go-sdk/pulls/545
Reviewed-by: Norwin <noerw@noreply.gitea.io>
Reviewed-by: techknowlogick <techknowlogick@gitea.io>
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-committed-by: Lunny Xiao <xiaolunwen@gmail.com>
This commit is contained in:
Lunny Xiao 2021-10-05 13:16:14 +08:00 committed by techknowlogick
parent 4debc6ca4b
commit bf0e0883a8
1 changed files with 8 additions and 1 deletions

View File

@ -6,6 +6,7 @@
package gitea
import (
"bytes"
"context"
"encoding/json"
"errors"
@ -192,7 +193,13 @@ func (c *Client) doRequest(method, path string, header http.Header, body io.Read
c.mutex.RLock()
debug := c.debug
if debug {
fmt.Printf("%s: %s\nHeader: %v\nBody: %s\n", method, c.url+"/api/v1"+path, header, body)
var bodyStr string
if body != nil {
bs, _ := ioutil.ReadAll(body)
body = bytes.NewReader(bs)
bodyStr = string(bs)
}
fmt.Printf("%s: %s\nHeader: %v\nBody: %s\n", method, c.url+"/api/v1"+path, header, bodyStr)
}
req, err := http.NewRequestWithContext(c.ctx, method, c.url+"/api/v1"+path, body)
if err != nil {