@@ -59,30 +59,60 @@ type EnvironmentConfig struct {
59
59
60
60
// ClientOptions holds optional configuration options for the HTTP Client.
61
61
type ClientOptions struct {
62
- EnableCookieJar bool // Field to enable or disable cookie jar
63
- LogLevel string // Field for defining tiered logging level.
64
- LogOutputFormat string // Field for defining the output format of the logs. Use "JSON" for JSON format, "console" for human-readable format
65
- LogConsoleSeparator string // Field for defining the separator in console output format.
66
- LogExportPath string // Field for specifying the path to output logs to.
67
- HideSensitiveData bool // Field for defining whether sensitive fields should be hidden in logs.
68
- MaxRetryAttempts int // Config item defines the max number of retry request attempts for retryable HTTP methods.
69
- EnableDynamicRateLimiting bool // Field for defining whether dynamic rate limiting should be enabled.
70
- MaxConcurrentRequests int // Field for defining the maximum number of concurrent requests allowed in the semaphore
71
- FollowRedirects bool // Flag to enable/disable following redirects
72
- MaxRedirects int // Maximum number of redirects to follow
73
- TokenRefreshBufferPeriod time.Duration
74
- TotalRetryDuration time.Duration
75
- CustomTimeout time.Duration
62
+ Logging LoggingConfig // Configuration related to logging
63
+ Cookie CookieConfig // Cookie handling settings
64
+ Retry RetryConfig // Retry behavior configuration
65
+ Concurrency ConcurrencyConfig // Concurrency configuration
66
+ Timeout TimeoutConfig // Custom timeout settings
67
+ Redirect RedirectConfig // Redirect handling settings
68
+ }
69
+
70
+ // LoggingConfig holds configuration options related to logging.
71
+ type LoggingConfig struct {
72
+ LogLevel string // Tiered logging level.
73
+ LogOutputFormat string // Output format of the logs. Use "JSON" for JSON format, "console" for human-readable format
74
+ LogConsoleSeparator string // Separator in console output format.
75
+ LogExportPath string // Path to output logs to.
76
+ HideSensitiveData bool // Whether sensitive fields should be hidden in logs.
77
+ }
78
+
79
+ // CookieConfig holds configuration related to cookie handling.
80
+ type CookieConfig struct {
81
+ EnableCookieJar bool // Enable or disable cookie jar
82
+ }
83
+
84
+ // RetryConfig holds configuration related to retry behavior.
85
+ type RetryConfig struct {
86
+ MaxRetryAttempts int // Maximum number of retry request attempts for retryable HTTP methods.
87
+ EnableDynamicRateLimiting bool // Whether dynamic rate limiting should be enabled.
88
+ }
89
+
90
+ // ConcurrencyConfig holds configuration related to concurrency management.
91
+ type ConcurrencyConfig struct {
92
+ MaxConcurrentRequests int // Maximum number of concurrent requests allowed.
93
+ }
94
+
95
+ // TimeoutConfig holds custom timeout settings.
96
+ type TimeoutConfig struct {
97
+ CustomTimeout time.Duration // Custom timeout for the HTTP client
98
+ TokenRefreshBufferPeriod time.Duration // Buffer period before token expiry to attempt token refresh
99
+ TotalRetryDuration time.Duration // Total duration to attempt retries
100
+ }
101
+
102
+ // RedirectConfig holds configuration related to redirect handling.
103
+ type RedirectConfig struct {
104
+ FollowRedirects bool // Enable or disable following redirects
105
+ MaxRedirects int // Maximum number of redirects to follow
76
106
}
77
107
78
108
// BuildClient creates a new HTTP client with the provided configuration.
79
109
func BuildClient (config ClientConfig ) (* Client , error ) {
80
110
81
111
// Parse the log level string to logger.LogLevel
82
- parsedLogLevel := logger .ParseLogLevelFromString (config .ClientOptions .LogLevel )
112
+ parsedLogLevel := logger .ParseLogLevelFromString (config .ClientOptions .Logging . LogLevel )
83
113
84
114
// Initialize the logger with parsed config values
85
- log := logger .BuildLogger (parsedLogLevel , config .ClientOptions .LogOutputFormat , config .ClientOptions .LogConsoleSeparator , config .ClientOptions .LogExportPath )
115
+ log := logger .BuildLogger (parsedLogLevel , config .ClientOptions .Logging . LogOutputFormat , config .ClientOptions .Logging . LogConsoleSeparator , config .ClientOptions . Logging .LogExportPath )
86
116
87
117
// Set the logger's level (optional if BuildLogger already sets the level based on the input)
88
118
log .SetLevel (parsedLogLevel )
@@ -114,24 +144,24 @@ func BuildClient(config ClientConfig) (*Client, error) {
114
144
authMethod ,
115
145
clientCredentials ,
116
146
config .Environment .InstanceName ,
117
- config .ClientOptions .HideSensitiveData ,
147
+ config .ClientOptions .Logging . HideSensitiveData ,
118
148
)
119
149
120
150
log .Info ("Initializing new HTTP client with the provided configuration" )
121
151
122
152
// Initialize the internal HTTP client
123
153
httpClient := & http.Client {
124
- Timeout : config .ClientOptions .CustomTimeout ,
154
+ Timeout : config .ClientOptions .Timeout . CustomTimeout ,
125
155
}
126
156
127
157
// Conditionally setup cookie jar
128
- if err := cookiejar .SetupCookieJar (httpClient , config .ClientOptions .EnableCookieJar , log ); err != nil {
158
+ if err := cookiejar .SetupCookieJar (httpClient , config .ClientOptions .Cookie . EnableCookieJar , log ); err != nil {
129
159
log .Error ("Error setting up cookie jar" , zap .Error (err ))
130
160
return nil , err
131
161
}
132
162
133
163
// Conditionally setup redirect handling
134
- if err := redirecthandler .SetupRedirectHandler (httpClient , config .ClientOptions .FollowRedirects , config .ClientOptions .MaxRedirects , log ); err != nil {
164
+ if err := redirecthandler .SetupRedirectHandler (httpClient , config .ClientOptions .Redirect . FollowRedirects , config .ClientOptions . Redirect .MaxRedirects , log ); err != nil {
135
165
log .Error ("Failed to set up redirect handler" , zap .Error (err ))
136
166
return nil , err
137
167
}
@@ -141,7 +171,7 @@ func BuildClient(config ClientConfig) (*Client, error) {
141
171
142
172
// Initialize the ConcurrencyHandler with the newly created ConcurrencyMetrics
143
173
concurrencyHandler := concurrency .NewConcurrencyHandler (
144
- config .ClientOptions .MaxConcurrentRequests ,
174
+ config .ClientOptions .Concurrency . MaxConcurrentRequests ,
145
175
log ,
146
176
concurrencyMetrics ,
147
177
)
@@ -165,19 +195,19 @@ func BuildClient(config ClientConfig) (*Client, error) {
165
195
zap .String ("Tenant ID" , config .Environment .TenantID ),
166
196
zap .String ("Tenant Name" , config .Environment .TenantName ),
167
197
zap .String ("Authentication Method" , authMethod ),
168
- zap .String ("Logging Level" , config .ClientOptions .LogLevel ),
169
- zap .String ("Log Encoding Format" , config .ClientOptions .LogOutputFormat ),
170
- zap .String ("Log Separator" , config .ClientOptions .LogConsoleSeparator ),
171
- zap .Bool ("Hide Sensitive Data In Logs" , config .ClientOptions .HideSensitiveData ),
172
- zap .Bool ("Cookie Jar Enabled" , config .ClientOptions .EnableCookieJar ),
173
- zap .Int ("Max Retry Attempts" , config .ClientOptions .MaxRetryAttempts ),
174
- zap .Int ( "Max Concurrent Requests " , config .ClientOptions .MaxConcurrentRequests ),
175
- zap .Bool ( "Follow Redirects " , config .ClientOptions .FollowRedirects ),
176
- zap .Int ( "Max Redirects" , config .ClientOptions .MaxRedirects ),
177
- zap .Bool ( "Enable Dynamic Rate Limiting " , config .ClientOptions .EnableDynamicRateLimiting ),
178
- zap .Duration ("Token Refresh Buffer Period" , config .ClientOptions .TokenRefreshBufferPeriod ),
179
- zap .Duration ("Total Retry Duration" , config .ClientOptions .TotalRetryDuration ),
180
- zap .Duration ("Custom Timeout" , config .ClientOptions .CustomTimeout ),
198
+ zap .String ("Logging Level" , config .ClientOptions .Logging . LogLevel ),
199
+ zap .String ("Log Encoding Format" , config .ClientOptions .Logging . LogOutputFormat ),
200
+ zap .String ("Log Separator" , config .ClientOptions .Logging . LogConsoleSeparator ),
201
+ zap .Bool ("Hide Sensitive Data In Logs" , config .ClientOptions .Logging . HideSensitiveData ),
202
+ zap .Bool ("Cookie Jar Enabled" , config .ClientOptions .Cookie . EnableCookieJar ),
203
+ zap .Int ("Max Retry Attempts" , config .ClientOptions .Retry . MaxRetryAttempts ),
204
+ zap .Bool ( "Enable Dynamic Rate Limiting " , config .ClientOptions .Retry . EnableDynamicRateLimiting ),
205
+ zap .Int ( "Max Concurrent Requests " , config .ClientOptions .Concurrency . MaxConcurrentRequests ),
206
+ zap .Bool ( "Follow Redirects" , config .ClientOptions .Redirect . FollowRedirects ),
207
+ zap .Int ( "Max Redirects " , config .ClientOptions .Redirect . MaxRedirects ),
208
+ zap .Duration ("Token Refresh Buffer Period" , config .ClientOptions .Timeout . TokenRefreshBufferPeriod ),
209
+ zap .Duration ("Total Retry Duration" , config .ClientOptions .Timeout . TotalRetryDuration ),
210
+ zap .Duration ("Custom Timeout" , config .ClientOptions .Timeout . CustomTimeout ),
181
211
)
182
212
183
213
return client , nil
0 commit comments