同步历史版本代码
This commit is contained in:
@@ -6,11 +6,10 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/go-resty/resty/v2"
|
||||
"github.com/perfect-panel/server/pkg/logger"
|
||||
)
|
||||
|
||||
const (
|
||||
Url = "https://api.apilayer.com"
|
||||
Url = "https://api.exchangerate.host"
|
||||
)
|
||||
|
||||
type Response struct {
|
||||
@@ -38,20 +37,18 @@ func GetExchangeRete(form, to, access string, amount float64) (float64, error) {
|
||||
amountStr := strconv.FormatFloat(amount, 'f', -1, 64)
|
||||
|
||||
client.SetQueryParams(map[string]string{
|
||||
"from": form,
|
||||
"to": to,
|
||||
"amount": amountStr,
|
||||
"from": form,
|
||||
"to": to,
|
||||
"amount": amountStr,
|
||||
"access_key": access,
|
||||
})
|
||||
result := new(Response)
|
||||
resp, err := client.R().SetHeader("apikey", access).SetResult(result).Get("/currency_data/convert")
|
||||
|
||||
resp := new(Response)
|
||||
_, err := client.R().SetResult(resp).Get("/convert")
|
||||
if err != nil {
|
||||
|
||||
return 0, err
|
||||
}
|
||||
if !result.Success {
|
||||
logger.Info("Exchange Rate Response: ", resp.String())
|
||||
if !resp.Success {
|
||||
return 0, errors.New("exchange rate failed")
|
||||
}
|
||||
return result.Result, nil
|
||||
return resp.Result, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user