Skip to content

Commit

Permalink
Merge pull request #6 from deploymenttheory/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
ShocOne authored Feb 8, 2024
2 parents bd5b7b0 + 6159d37 commit d85be94
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
27 changes: 16 additions & 11 deletions httpclient/httpclient_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import (
type Config struct {
// Required
InstanceName string
Auth AuthConfig // User can either supply these values manually or pass from LoadAuthConfig/Env vars
APIType string `json:"apiType"`
Auth AuthConfig // User can either supply these values manually or pass from LoadAuthConfig/Env vars
APIType EnvironmentConfig // User can either supply these values manually or pass from LoadAuthConfig/Env vars
// Optional
LogLevel logger.LogLevel // Field for defining tiered logging level.
MaxRetryAttempts int // Config item defines the max number of retry request attempts for retryable HTTP methods.
Expand All @@ -43,14 +43,19 @@ type PerformanceMetrics struct {
lock sync.Mutex
}

// ClientAuthConfig represents the structure to read authentication details from a JSON configuration file.
type AuthConfig struct {
// EnvironmentConfig represents the structure to read authentication details from a JSON configuration file.
type EnvironmentConfig struct {
InstanceName string `json:"instanceName,omitempty"`
OverrideBaseDomain string `json:"overrideBaseDomain,omitempty"`
Username string `json:"username,omitempty"`
Password string `json:"password,omitempty"`
ClientID string `json:"clientID,omitempty"`
ClientSecret string `json:"clientSecret,omitempty"`
APIType string `json:"apiType,omitempty"`
}

// AuthConfig represents the structure to read authentication details from a JSON configuration file.
type AuthConfig struct {
Username string `json:"username,omitempty"`
Password string `json:"password,omitempty"`
ClientID string `json:"clientID,omitempty"`
ClientSecret string `json:"clientSecret,omitempty"`
}

// Client represents an HTTP client to interact with a specific API.
Expand Down Expand Up @@ -84,14 +89,14 @@ func BuildClient(config Config) (*Client, error) {
}

// Use the APIType from the config to determine which API handler to load
apiHandler, err := LoadAPIHandler(config.APIType, log)
apiHandler, err := LoadAPIHandler(config.APIType.APIType, log)
if err != nil {
return nil, log.Error("Failed to load API handler", zap.String("APIType", config.APIType), zap.Error(err))
return nil, log.Error("Failed to load API handler", zap.String("APIType", config.APIType.APIType), zap.Error(err))
}

log.Info("Initializing new HTTP client",
zap.String("InstanceName", config.InstanceName), // Using zap.String for structured logging
zap.String("APIType", config.APIType), // Using zap.String for structured logging
zap.String("APIType", config.APIType.APIType), // Using zap.String for structured logging
zap.Int("LogLevel", int(config.LogLevel)), // Using zap.Int to log LogLevel as an integer
)

Expand Down
4 changes: 2 additions & 2 deletions logger/loggerconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ func BuildLogger(logLevel LogLevel) Logger {
Level: zap.NewAtomicLevelAt(zapLogLevel), // Default log level is Info
Development: false, // Set to true if the logger is used in a development environment
Encoding: "json", // Use JSON format for structured logging
DisableCaller: false,
DisableStacktrace: false,
DisableCaller: true,
DisableStacktrace: true,
Sampling: nil,
EncoderConfig: encoderCfg,
OutputPaths: []string{
Expand Down

0 comments on commit d85be94

Please sign in to comment.