removed HTTPClientConfigInterface because it breaks configuration unmarshaling

This commit is contained in:
Pavel 2019-12-13 12:13:57 +03:00
parent 6057e3cb4f
commit 9bd8eca75a
4 changed files with 23 additions and 46 deletions

View File

@ -30,7 +30,7 @@ type ConfigInterface interface {
GetDBConfig() DatabaseConfig
GetAWSConfig() ConfigAWS
GetTransportInfo() InfoInterface
GetHTTPClientConfig() HTTPClientConfigInterface
GetHTTPClientConfig() *HTTPClientConfig
GetUpdateInterval() int
IsDebug() bool
}
@ -42,14 +42,6 @@ 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"`
@ -61,7 +53,7 @@ type Config struct {
UpdateInterval int `yaml:"update_interval"`
ConfigAWS ConfigAWS `yaml:"config_aws"`
TransportInfo Info `yaml:"transport_info"`
HTTPClientConfig HTTPClientConfigInterface `yaml:"http_client"`
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
}

View File

@ -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

View File

@ -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())

View File

@ -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() {