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

View file

@ -6,6 +6,7 @@
package gitea package gitea
import ( import (
"bytes"
"context" "context"
"encoding/json" "encoding/json"
"errors" "errors"
@ -192,7 +193,13 @@ func (c *Client) doRequest(method, path string, header http.Header, body io.Read
c.mutex.RLock() c.mutex.RLock()
debug := c.debug debug := c.debug
if 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) req, err := http.NewRequestWithContext(c.ctx, method, c.url+"/api/v1"+path, body)
if err != nil { if err != nil {