Skip to content

Commit f49f097

Browse files
authored
Merge pull request #7 from deploymenttheory/dev
Refactor Config struct in httpclient_client.go
2 parents d85be94 + ea524fd commit f49f097

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

httpclient/httpclient_client.go

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,8 @@ import (
1919
// Config holds configuration options for the HTTP Client.
2020
type Config struct {
2121
// Required
22-
InstanceName string
23-
Auth AuthConfig // User can either supply these values manually or pass from LoadAuthConfig/Env vars
24-
APIType EnvironmentConfig // User can either supply these values manually or pass from LoadAuthConfig/Env vars
22+
Auth AuthConfig // User can either supply these values manually or pass from LoadAuthConfig/Env vars
23+
Environment EnvironmentConfig // User can either supply these values manually or pass from LoadAuthConfig/Env vars
2524
// Optional
2625
LogLevel logger.LogLevel // Field for defining tiered logging level.
2726
MaxRetryAttempts int // Config item defines the max number of retry request attempts for retryable HTTP methods.
@@ -89,19 +88,19 @@ func BuildClient(config Config) (*Client, error) {
8988
}
9089

9190
// Use the APIType from the config to determine which API handler to load
92-
apiHandler, err := LoadAPIHandler(config.APIType.APIType, log)
91+
apiHandler, err := LoadAPIHandler(config.Environment.APIType, log)
9392
if err != nil {
94-
return nil, log.Error("Failed to load API handler", zap.String("APIType", config.APIType.APIType), zap.Error(err))
93+
return nil, log.Error("Failed to load API handler", zap.String("APIType", config.Environment.APIType), zap.Error(err))
9594
}
9695

9796
log.Info("Initializing new HTTP client",
98-
zap.String("InstanceName", config.InstanceName), // Using zap.String for structured logging
99-
zap.String("APIType", config.APIType.APIType), // Using zap.String for structured logging
100-
zap.Int("LogLevel", int(config.LogLevel)), // Using zap.Int to log LogLevel as an integer
97+
zap.String("InstanceName", config.Environment.APIType), // Using zap.String for structured logging
98+
zap.String("APIType", config.Environment.APIType), // Using zap.String for structured logging
99+
zap.Int("LogLevel", int(config.LogLevel)), // Using zap.Int to log LogLevel as an integer
101100
)
102101

103102
// Validate and set default values for the configuration
104-
if config.InstanceName == "" {
103+
if config.Environment.APIType == "" {
105104
return nil, log.Error("InstanceName cannot be empty")
106105
}
107106

@@ -151,7 +150,7 @@ func BuildClient(config Config) (*Client, error) {
151150
}
152151

153152
client := &Client{
154-
InstanceName: config.InstanceName,
153+
InstanceName: config.Environment.APIType,
155154
APIHandler: apiHandler,
156155
AuthMethod: AuthMethod,
157156
httpClient: &http.Client{Timeout: config.CustomTimeout},

0 commit comments

Comments
 (0)