mirror of
https://github.com/plutov/paypal.git
synced 2025-01-23 10:21:03 +01:00
CHANGE: Renamed 'SetLogFile' to 'SetLog' and changed the parameter from a string to io.Writer
CHANGE: Changed logFile name and type to name Log of type io.Writer CHANGE: func log of client now uses new log object.
This commit is contained in:
parent
86a0467076
commit
f6bd5b385e
22
client.go
22
client.go
|
@ -8,7 +8,6 @@ import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httputil"
|
"net/http/httputil"
|
||||||
"os"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// NewClient returns new Client struct
|
// NewClient returns new Client struct
|
||||||
|
@ -23,16 +22,15 @@ func NewClient(clientID string, secret string, APIBase string) (*Client, error)
|
||||||
clientID,
|
clientID,
|
||||||
secret,
|
secret,
|
||||||
APIBase,
|
APIBase,
|
||||||
"",
|
nil,
|
||||||
nil,
|
nil,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetLogFile will set/change a full path to a log file
|
// SetLog will set/change the output destination.
|
||||||
// If log file is set paypalsdk will log all requests and responses to this file
|
// If log file is set paypalsdk will log all requests and responses to this Writer
|
||||||
func (c *Client) SetLogFile(filepath string) error {
|
func (c *Client) SetLog(log io.Writer) error {
|
||||||
c.LogFile = filepath
|
c.Log = log
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -119,15 +117,11 @@ func (c *Client) NewRequest(method, url string, payload interface{}) (*http.Requ
|
||||||
|
|
||||||
// log will dump request and response to the log file
|
// log will dump request and response to the log file
|
||||||
func (c *Client) log(req *http.Request, resp *http.Response) {
|
func (c *Client) log(req *http.Request, resp *http.Response) {
|
||||||
if c.LogFile != "" {
|
if c.Log != nil {
|
||||||
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 {
|
|
||||||
reqDump, _ := httputil.DumpRequestOut(req, true)
|
reqDump, _ := httputil.DumpRequestOut(req, true)
|
||||||
respDump, _ := httputil.DumpResponse(resp, true)
|
respDump, _ := httputil.DumpResponse(resp, true)
|
||||||
|
|
||||||
logFile.WriteString("Request: " + string(reqDump) + "\nResponse: " + string(respDump) + "\n\n")
|
c.Log.Write([]byte("Request: " + string(reqDump) + "\nResponse: " + string(respDump) + "\n\n"))
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
3
types.go
3
types.go
|
@ -4,6 +4,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"time"
|
"time"
|
||||||
|
"io"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -82,7 +83,7 @@ type (
|
||||||
ClientID string
|
ClientID string
|
||||||
Secret string
|
Secret string
|
||||||
APIBase string
|
APIBase string
|
||||||
LogFile string // If user set log file name all requests will be logged there
|
Log io.Writer // If user set log file name all requests will be logged there
|
||||||
Token *TokenResponse
|
Token *TokenResponse
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user