-
Notifications
You must be signed in to change notification settings - Fork 3
/
client_options.go
59 lines (51 loc) · 1.18 KB
/
client_options.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
52
53
54
55
56
57
58
59
/*
* Go OAuth2 Client
*
* MIT License
*
* Copyright (c) 2015 Globo.com
*/
package galf
import "time"
const (
DefaultClientTimeout = 20 * time.Second
DefaultClientMaxRetries = 2
DefaultContentType = "application/json"
)
type (
ClientOptions struct {
ContentType string
Timeout time.Duration
Backoff BackoffStrategy
MaxRetries int
ShowDebug bool
HystrixConfig *HystrixConfig
}
)
var (
defaultClientOptions = ClientOptions{
ContentType: DefaultContentType,
Timeout: DefaultClientTimeout,
MaxRetries: DefaultClientMaxRetries,
Backoff: ConstantBackOff,
ShowDebug: false,
HystrixConfig: nil,
}
)
func NewClientOptions(timeout time.Duration, debug bool, maxRetries int, hystrixConfigName string, backoff ...BackoffStrategy) ClientOptions {
clientBackoff := ConstantBackOff
if len(backoff) > 0 {
clientBackoff = backoff[0]
}
var hystrixConfig *HystrixConfig
if hystrixConfigName != "" {
hystrixConfig = NewHystrixConfig(hystrixConfigName)
}
return ClientOptions{
Timeout: timeout,
ShowDebug: debug,
MaxRetries: maxRetries,
Backoff: clientBackoff,
HystrixConfig: hystrixConfig,
}
}