Move PrintDebugRequest() and PrintDebugResponse() calls in client to hooks

This commit is contained in:
Juan Carlos Mejías Rodríguez 2019-08-05 23:23:16 -04:00
parent 76d92c5885
commit 5748d862bb
2 changed files with 18 additions and 5 deletions

View File

@ -113,8 +113,6 @@ func (n *portainerClientImp) do(uri, method string, request io.Reader, requestTy
}
}
util.PrintDebugRequest("Request", req)
resp, err = n.httpClient.Do(req)
if err != nil {
return
@ -133,8 +131,6 @@ func (n *portainerClientImp) do(uri, method string, request io.Reader, requestTy
return
}
util.PrintDebugResponse("Response", resp)
return
}

View File

@ -4,6 +4,8 @@ import (
"crypto/tls"
"net/http"
"github.com/greenled/portainer-stack-utils/util"
"github.com/greenled/portainer-stack-utils/client"
"github.com/spf13/viper"
@ -24,7 +26,22 @@ func GetClient() (c client.PortainerClient, err error) {
// Get the default client
func GetDefaultClient() (c client.PortainerClient, err error) {
return client.NewClient(GetDefaultHttpClient(), GetDefaultClientConfig())
c, err = client.NewClient(GetDefaultHttpClient(), GetDefaultClientConfig())
if err != nil {
return
}
c.BeforeRequest(func(req *http.Request) (err error) {
util.PrintDebugRequest("Request", req)
return
})
c.AfterResponse(func(resp *http.Response) (err error) {
util.PrintDebugResponse("Response", resp)
return
})
return
}
// Get the default config for a client