2021-11-22 17:28:18 +00:00
|
|
|
package web
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/hashicorp/go-retryablehttp"
|
|
|
|
"github.com/sirupsen/logrus"
|
|
|
|
)
|
|
|
|
|
2021-12-19 14:46:26 +00:00
|
|
|
// customLeveledLogger is custom logger with logrus baked in
|
2021-11-22 17:28:18 +00:00
|
|
|
type customLeveledLogger struct {
|
|
|
|
retryablehttp.Logger
|
|
|
|
}
|
|
|
|
|
2021-12-19 14:46:26 +00:00
|
|
|
// Printf wires up logrus into the custom retryablehttp logger
|
2021-11-22 17:28:18 +00:00
|
|
|
func (l customLeveledLogger) Printf(msg string, args ...interface{}) {
|
|
|
|
logrus.Debugf(fmt.Sprintf(msg, args...))
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewHTTPRetryClient instantiates a new http client with retries baked in
|
|
|
|
func NewHTTPRetryClient() *retryablehttp.Client {
|
|
|
|
retryClient := retryablehttp.NewClient()
|
|
|
|
retryClient.Logger = customLeveledLogger{}
|
|
|
|
return retryClient
|
|
|
|
}
|