refactor exchange rates data backend, supports multi data source, supports timeout

This commit is contained in:
MaysWind
2021-01-10 01:07:37 +08:00
parent 170780a631
commit dff54fd174
9 changed files with 211 additions and 85 deletions
@@ -0,0 +1,26 @@
package exchangerates
import (
"github.com/mayswind/lab/pkg/errs"
"github.com/mayswind/lab/pkg/settings"
)
// ExchangeRatesDataSourceContainer contains the current exchange rates data source
type ExchangeRatesDataSourceContainer struct {
Current ExchangeRatesDataSource
}
// Initialize a exchange rates data source container singleton instance
var (
Container = &ExchangeRatesDataSourceContainer{}
)
// InitializeExchangeRatesDataSource initializes the current exchange rates data source according to the config
func InitializeExchangeRatesDataSource(config *settings.Config) error {
if config.ExchangeRatesDataSource == settings.EuroCentralBankDataSource {
Container.Current = &EuroCentralBankDataSource{}
return nil
}
return errs.ErrInvalidExchangeRatesDataSource
}