-
Notifications
You must be signed in to change notification settings - Fork 4
/
cli.go
51 lines (38 loc) · 1.06 KB
/
cli.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// Unless explicitly stated otherwise all files in this repository are licensed
// under the MIT License.
// This product includes software developed at Guance Cloud (https://www.guance.com/).
// Copyright 2021-present Guance, Inc.
package refertable
import (
"net/http"
"time"
"github.com/hashicorp/go-retryablehttp"
)
type cliLogger struct{}
func (*cliLogger) Error(msg string, kv ...any) {
l.Error(msg, kv)
}
func (*cliLogger) Warn(msg string, kv ...any) {
l.Warn(msg, kv)
}
func (*cliLogger) Info(msg string, kv ...any) {
l.Info(msg, kv)
}
func (*cliLogger) Debug(msg string, kv ...any) {
l.Debug(msg, kv)
}
func newRetryCli(client *http.Client, timeout time.Duration) *retryablehttp.Client {
cli := retryablehttp.NewClient()
cli.RetryMax = 3
cli.RetryWaitMin = time.Second
cli.RetryWaitMax = time.Second * 5
cli.RequestLogHook = func(_ retryablehttp.Logger, r *http.Request, n int) {
if n > 0 {
l.Warnf("retry %d time on API %s", n, r.URL.Path)
}
}
cli.HTTPClient = client
cli.HTTPClient.Timeout = timeout
cli.Logger = &cliLogger{}
return cli
}