From b4cd3d758cafce9f79a502b247474e1990f0809a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B1=88=E8=BD=A9?= Date: Tue, 21 May 2024 19:22:00 +0800 Subject: [PATCH] fix(region): currency rate exchange (#20334) --- pkg/util/yunionmeta/meta.go | 6 +++--- pkg/util/yunionmeta/meta_test.go | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pkg/util/yunionmeta/meta.go b/pkg/util/yunionmeta/meta.go index e224d7c786..98764291a8 100644 --- a/pkg/util/yunionmeta/meta.go +++ b/pkg/util/yunionmeta/meta.go @@ -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) } diff --git a/pkg/util/yunionmeta/meta_test.go b/pkg/util/yunionmeta/meta_test.go index 9d80771561..8e33e13a11 100644 --- a/pkg/util/yunionmeta/meta_test.go +++ b/pkg/util/yunionmeta/meta_test.go @@ -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) }