Skip to content

Commit

Permalink
fix(region): currency rate exchange (#20335)
Browse files Browse the repository at this point in the history
  • Loading branch information
ioito committed May 21, 2024
1 parent f91ceb8 commit 78a1832
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions pkg/util/yunionmeta/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/util/yunionmeta/meta_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit 78a1832

Please sign in to comment.