From c001a5ae45cc0250edf51c3771577c336aceb062 Mon Sep 17 00:00:00 2001 From: MaysWind Date: Mon, 5 Apr 2021 01:11:22 +0800 Subject: [PATCH] don't add exchange rate item to result if rate is invalid --- pkg/exchangerates/euro_central_bank_datasource.go | 5 +++++ pkg/exchangerates/reserve_bank_of_australia_datasource.go | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/pkg/exchangerates/euro_central_bank_datasource.go b/pkg/exchangerates/euro_central_bank_datasource.go index e529adc2..6f5cb3e6 100644 --- a/pkg/exchangerates/euro_central_bank_datasource.go +++ b/pkg/exchangerates/euro_central_bank_datasource.go @@ -9,6 +9,7 @@ import ( "github.com/mayswind/lab/pkg/log" "github.com/mayswind/lab/pkg/models" "github.com/mayswind/lab/pkg/validators" + "github.com/mayswind/lab/pkg/utils" ) const euroCentralBankExchangeRateUrl = "https://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml" @@ -65,6 +66,10 @@ func (e *EuroCentralBankExchangeRateData) ToLatestExchangeRateResponse(c *core.C continue } + if _, err := utils.StringToFloat64(exchangeRate.Rate); err != nil { + continue + } + exchangeRates = append(exchangeRates, exchangeRate.ToLatestExchangeRate()) } diff --git a/pkg/exchangerates/reserve_bank_of_australia_datasource.go b/pkg/exchangerates/reserve_bank_of_australia_datasource.go index 93cb07bf..ec114cd7 100644 --- a/pkg/exchangerates/reserve_bank_of_australia_datasource.go +++ b/pkg/exchangerates/reserve_bank_of_australia_datasource.go @@ -8,6 +8,7 @@ import ( "github.com/mayswind/lab/pkg/errs" "github.com/mayswind/lab/pkg/log" "github.com/mayswind/lab/pkg/models" + "github.com/mayswind/lab/pkg/utils" "github.com/mayswind/lab/pkg/validators" ) @@ -87,6 +88,10 @@ func (e *ReserveBankOfAustraliaData) ToLatestExchangeRateResponse(c *core.Contex continue } + if _, err := utils.StringToFloat64(item.Statistics.ExchangeRate.Observation.Value); err != nil { + continue + } + exchangeRates = append(exchangeRates, item.Statistics.ExchangeRate.ToLatestExchangeRate()) }