mirror of
https://github.com/retailcrm/mg-transport-core.git
synced 2024-11-25 14:46:02 +03:00
removed HTTPClientConfigInterface because it breaks configuration unmarshaling
This commit is contained in:
parent
6057e3cb4f
commit
9bd8eca75a
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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())
|
||||
|
@ -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() {
|
||||
|
Loading…
Reference in New Issue
Block a user