-
Notifications
You must be signed in to change notification settings - Fork 0
/
httpConfiguration.go
62 lines (51 loc) · 1.91 KB
/
httpConfiguration.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
60
61
62
package https
import (
"net/http"
)
// HttpConfigurationOptions is a function type that takes a pointer to HttpConfiguration as input and modifies it.
type HttpConfigurationOptions func(*HttpConfiguration)
// HttpConfiguration holds the configuration options for the HTTP client.
type HttpConfiguration struct {
timeout float64
transport http.RoundTripper
retryConfiguration RetryConfiguration
}
// Timeout returns the configured timeout value for the HTTP client.
func (h *HttpConfiguration) Timeout() float64 {
return h.timeout
}
// Transport returns the configured custom HTTP transport for the HTTP client.
func (h *HttpConfiguration) Transport() http.RoundTripper {
return h.transport
}
// RetryConfiguration returns the configured retry configuration for the HTTP client.
func (h *HttpConfiguration) RetryConfiguration() RetryConfiguration {
return h.retryConfiguration
}
// NewHttpConfiguration creates a new HttpConfiguration with the provided options and returns it.
// The options parameter allows setting different configuration options for the HTTP client.
func NewHttpConfiguration(options ...HttpConfigurationOptions) HttpConfiguration {
httpConfiguration := HttpConfiguration{}
for _, option := range options {
option(&httpConfiguration)
}
return httpConfiguration
}
// WithTimeout sets the timeout for the HTTP client.
func WithTimeout(timeout float64) HttpConfigurationOptions {
return func(h *HttpConfiguration) {
h.timeout = timeout
}
}
// WithTransport sets the custom HTTP transport for the HTTP client.
func WithTransport(transport http.RoundTripper) HttpConfigurationOptions {
return func(h *HttpConfiguration) {
h.transport = transport
}
}
// WithRetryConfiguration sets the retry configuration for the HTTP client.
func WithRetryConfiguration(retryConfig RetryConfiguration) HttpConfigurationOptions {
return func(h *HttpConfiguration) {
h.retryConfiguration = retryConfig
}
}