mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
fix(region): currency rate exchange (#20334)
This commit is contained in:
@@ -115,15 +115,15 @@ func (self *SSkuResourcesMeta) head(url string) (http.Header, jsonutils.JSONObje
|
||||
return _header, resp, err
|
||||
}
|
||||
|
||||
func (self *SSkuResourcesMeta) GetCurrencyRate(currency string) (float64, error) {
|
||||
url := fmt.Sprintf("%s/%s", self.CurrencyExchangeBase, currency)
|
||||
func (self *SSkuResourcesMeta) GetCurrencyRate(src, dest string) (float64, error) {
|
||||
url := fmt.Sprintf("%s/%s-%s", self.CurrencyExchangeBase, src, dest)
|
||||
header, _, err := self.head(url)
|
||||
if err != nil {
|
||||
return 0.0, errors.Wrapf(err, "head %s", url)
|
||||
}
|
||||
rate := header.Get("x-oss-meta-rate")
|
||||
if len(rate) == 0 {
|
||||
return 0.0, errors.Wrapf(cloudprovider.ErrNotFound, "x-oss-meta-rate %s", currency)
|
||||
return 0.0, errors.Wrapf(cloudprovider.ErrNotFound, "x-oss-meta-rate %s -> %s", src, dest)
|
||||
}
|
||||
return strconv.ParseFloat(rate, 64)
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ func TestCurrencyRate(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("Unmarshal meta error: %v", err)
|
||||
}
|
||||
rate, err := meta.GetCurrencyRate("USD")
|
||||
rate, err := meta.GetCurrencyRate("CNY", "USD")
|
||||
if err != nil {
|
||||
t.Fatalf("get used rate error: %v", rate)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user