diff --git a/client/client.go b/client/client.go index 9bd97a8..d8451ad 100644 --- a/client/client.go +++ b/client/client.go @@ -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 } diff --git a/common/client.go b/common/client.go index 191637d..14e8625 100644 --- a/common/client.go +++ b/common/client.go @@ -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