mirror of
https://github.com/plutov/paypal.git
synced 2025-02-02 15:10:36 +01:00
log
This commit is contained in:
parent
3e1a1f8ddd
commit
5043557577
22
client.go
22
client.go
|
@ -6,6 +6,7 @@ import (
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
// NewClient returns new Client struct
|
// NewClient returns new Client struct
|
||||||
|
@ -19,10 +20,18 @@ func NewClient(clientID string, secret string, APIBase string) (*Client, error)
|
||||||
clientID,
|
clientID,
|
||||||
secret,
|
secret,
|
||||||
APIBase,
|
APIBase,
|
||||||
|
"",
|
||||||
nil,
|
nil,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetLogFile func
|
||||||
|
func (c *Client) SetLogFile(filepath string) error {
|
||||||
|
c.LogFile = filepath
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// SetAccessToken sets saved token to current client
|
// SetAccessToken sets saved token to current client
|
||||||
func (c *Client) SetAccessToken(token string) error {
|
func (c *Client) SetAccessToken(token string) error {
|
||||||
c.Token = &TokenResponse{
|
c.Token = &TokenResponse{
|
||||||
|
@ -46,6 +55,8 @@ func (c *Client) Send(req *http.Request, v interface{}) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
resp, err := c.client.Do(req)
|
resp, err := c.client.Do(req)
|
||||||
|
c.log(req, resp)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -75,3 +86,14 @@ func (c *Client) Send(req *http.Request, v interface{}) error {
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *Client) log(request *http.Request, response *http.Response) {
|
||||||
|
if c.LogFile != "" {
|
||||||
|
os.OpenFile(c.LogFile, os.O_CREATE, 0755)
|
||||||
|
|
||||||
|
logFile, err := os.OpenFile(c.LogFile, os.O_APPEND|os.O_RDWR|os.O_CREATE, 0755)
|
||||||
|
if err == nil {
|
||||||
|
logFile.WriteString("URL: " + request.RequestURI + "\n\n")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user