refactor exchange rates data backend, supports multi data source, supports timeout
This commit is contained in:
@@ -62,6 +62,11 @@ const (
|
||||
InternalUuidGeneratorType string = "internal"
|
||||
)
|
||||
|
||||
// Exchange rates data source types
|
||||
const (
|
||||
EuroCentralBankDataSource string = "euro_central_bank"
|
||||
)
|
||||
|
||||
const (
|
||||
defaultAppName string = "lab"
|
||||
|
||||
@@ -81,6 +86,8 @@ const (
|
||||
defaultSecretKey string = "lab"
|
||||
defaultTokenExpiredTime int = 604800 // 7 days
|
||||
defaultTemporaryTokenExpiredTime int = 300 // 5 minutes
|
||||
|
||||
defaultExchangeRatesDataRequestTimeout int = 10000 // 10 seconds
|
||||
)
|
||||
|
||||
// DatabaseConfig represents the database setting config
|
||||
@@ -156,6 +163,10 @@ type Config struct {
|
||||
|
||||
// Data
|
||||
EnableDataExport bool
|
||||
|
||||
// Exchange Rates
|
||||
ExchangeRatesDataSource string
|
||||
ExchangeRatesRequestTimeout int
|
||||
}
|
||||
|
||||
// LoadConfiguration loads setting config from given config file path
|
||||
@@ -223,6 +234,12 @@ func LoadConfiguration(configFilePath string) (*Config, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = loadExchangeRatesConfiguration(config, cfgFile, "exchange_rates")
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return config, nil
|
||||
}
|
||||
|
||||
@@ -392,6 +409,18 @@ func loadDataConfiguration(config *Config, configFile *ini.File, sectionName str
|
||||
return nil
|
||||
}
|
||||
|
||||
func loadExchangeRatesConfiguration(config *Config, configFile *ini.File, sectionName string) error {
|
||||
if getConfigItemStringValue(configFile, sectionName, "data_source") == EuroCentralBankDataSource {
|
||||
config.ExchangeRatesDataSource = EuroCentralBankDataSource
|
||||
} else {
|
||||
return errs.ErrInvalidExchangeRatesDataSource
|
||||
}
|
||||
|
||||
config.ExchangeRatesRequestTimeout = getConfigItemIntValue(configFile, sectionName, "request_timeout", defaultExchangeRatesDataRequestTimeout)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func getWorkingPath() (string, error) {
|
||||
workingPath := os.Getenv(labWorkDirEnvName)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user