From 9bd8eca75a158dde3ad881384d4d2b7ab0ac6a0c Mon Sep 17 00:00:00 2001 From: Pavel Date: Fri, 13 Dec 2019 12:13:57 +0300 Subject: [PATCH] removed HTTPClientConfigInterface because it breaks configuration unmarshaling --- core/config.go | 51 ++++++++------------------------ core/config_test.go | 4 +++ core/http_client_builder.go | 12 ++++---- core/http_client_builder_test.go | 2 +- 4 files changed, 23 insertions(+), 46 deletions(-) diff --git a/core/config.go b/core/config.go index 7206c31..cf06682 100644 --- a/core/config.go +++ b/core/config.go @@ -30,7 +30,7 @@ type ConfigInterface interface { GetDBConfig() DatabaseConfig GetAWSConfig() ConfigAWS GetTransportInfo() InfoInterface - GetHTTPClientConfig() HTTPClientConfigInterface + GetHTTPClientConfig() *HTTPClientConfig GetUpdateInterval() int IsDebug() bool } @@ -42,26 +42,18 @@ type InfoInterface interface { GetLogoPath() string } -// HTTPClientConfigInterface can be used to provide alternative way for configuring HTTP server -type HTTPClientConfigInterface interface { - GetTimeout() time.Duration - IsSSLVerificationEnabled() bool - GetMockAddress() string - GetMockedDomains() []string -} - // Config struct type Config struct { - Version string `yaml:"version"` - LogLevel logging.Level `yaml:"log_level"` - Database DatabaseConfig `yaml:"database"` - SentryDSN string `yaml:"sentry_dsn"` - HTTPServer HTTPServerConfig `yaml:"http_server"` - Debug bool `yaml:"debug"` - UpdateInterval int `yaml:"update_interval"` - ConfigAWS ConfigAWS `yaml:"config_aws"` - TransportInfo Info `yaml:"transport_info"` - HTTPClientConfig HTTPClientConfigInterface `yaml:"http_client"` + Version string `yaml:"version"` + LogLevel logging.Level `yaml:"log_level"` + Database DatabaseConfig `yaml:"database"` + SentryDSN string `yaml:"sentry_dsn"` + HTTPServer HTTPServerConfig `yaml:"http_server"` + Debug bool `yaml:"debug"` + UpdateInterval int `yaml:"update_interval"` + ConfigAWS ConfigAWS `yaml:"config_aws"` + TransportInfo Info `yaml:"transport_info"` + HTTPClientConfig *HTTPClientConfig `yaml:"http_client"` } // Info struct @@ -189,7 +181,7 @@ func (c Config) GetUpdateInterval() int { } // GetHTTPClientConfig returns http client config -func (c Config) GetHTTPClientConfig() HTTPClientConfigInterface { +func (c Config) GetHTTPClientConfig() *HTTPClientConfig { return c.HTTPClientConfig } @@ -208,15 +200,6 @@ func (t Info) GetLogoPath() string { return t.LogoPath } -// GetTimeout returns timeout for HTTP client (default is 30 seconds) -func (h *HTTPClientConfig) GetTimeout() time.Duration { - if h.Timeout <= 0 { - h.Timeout = 30 * time.Second - } - - return h.Timeout -} - // IsSSLVerificationEnabled returns SSL verification flag (default is true) func (h *HTTPClientConfig) IsSSLVerificationEnabled() bool { if h.SSLVerification == nil { @@ -225,13 +208,3 @@ func (h *HTTPClientConfig) IsSSLVerificationEnabled() bool { return *h.SSLVerification } - -// GetMockAddress returns mock address -func (h *HTTPClientConfig) GetMockAddress() string { - return h.MockAddress -} - -// GetMockedDomains returns mocked domains list -func (h *HTTPClientConfig) GetMockedDomains() []string { - return h.MockedDomains -} diff --git a/core/config_test.go b/core/config_test.go index 9c796f2..047b79a 100644 --- a/core/config_test.go +++ b/core/config_test.go @@ -41,6 +41,10 @@ log_level: 5 debug: true update_interval: 24 +http_client: + ssl_verification: false + timeout: 30 + config_aws: access_key_id: key secret_access_key: secret diff --git a/core/http_client_builder.go b/core/http_client_builder.go index a945468..41d1731 100644 --- a/core/http_client_builder.go +++ b/core/http_client_builder.go @@ -122,18 +122,18 @@ func (b *HTTPClientBuilder) SetLogging(flag bool) *HTTPClientBuilder { } // FromConfig fulfills mock configuration from HTTPClientConfig -func (b *HTTPClientBuilder) FromConfig(config HTTPClientConfigInterface) *HTTPClientBuilder { +func (b *HTTPClientBuilder) FromConfig(config *HTTPClientConfig) *HTTPClientBuilder { if config == nil { return b } - if config.GetMockAddress() != "" { - b.SetMockAddress(config.GetMockAddress()) - b.SetMockedDomains(config.GetMockedDomains()) + if config.MockAddress != "" { + b.SetMockAddress(config.MockAddress) + b.SetMockedDomains(config.MockedDomains) } - if config.GetTimeout() > 0 { - b.SetTimeout(config.GetTimeout()) + if config.Timeout > 0 { + b.SetTimeout(config.Timeout) } b.SetSSLVerification(config.IsSSLVerificationEnabled()) diff --git a/core/http_client_builder_test.go b/core/http_client_builder_test.go index 2d56ed3..f374d89 100644 --- a/core/http_client_builder_test.go +++ b/core/http_client_builder_test.go @@ -102,7 +102,7 @@ func (t *HTTPClientBuilderTest) Test_FromEngine() { } t.builder.FromEngine(engine) - assert.Equal(t.T(), engine.Config.GetHTTPClientConfig().GetMockAddress(), t.builder.mockAddress) + assert.Equal(t.T(), engine.Config.GetHTTPClientConfig().MockAddress, t.builder.mockAddress) } func (t *HTTPClientBuilderTest) Test_buildDialer() {