don't add exchange rate item to result if rate is invalid

This commit is contained in:
MaysWind
2021-04-05 01:11:22 +08:00
parent eaee3678d7
commit c001a5ae45
2 changed files with 10 additions and 0 deletions
@@ -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())
}
@@ -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())
}