parent
5a03b38b32
commit
90dd06676c
|
@ -16,6 +16,9 @@ import (
|
||||||
|
|
||||||
var (
|
var (
|
||||||
updateUrl = "https://www.mycurrency.net/=US"
|
updateUrl = "https://www.mycurrency.net/=US"
|
||||||
|
codeAliases = map[string]string{
|
||||||
|
"CNH": "CNY",
|
||||||
|
}
|
||||||
|
|
||||||
client = resty.New()
|
client = resty.New()
|
||||||
)
|
)
|
||||||
|
@ -63,14 +66,19 @@ func parse(body []byte) (map[string]*Currency, error) {
|
||||||
doc.Find("tr.country").Each(func(_ int, s *goquery.Selection) {
|
doc.Find("tr.country").Each(func(_ int, s *goquery.Selection) {
|
||||||
var (
|
var (
|
||||||
c Currency
|
c Currency
|
||||||
|
code string
|
||||||
isoC iso.ISOCurrency
|
isoC iso.ISOCurrency
|
||||||
ok bool
|
ok bool
|
||||||
err error
|
err error
|
||||||
rate string
|
rate string
|
||||||
)
|
)
|
||||||
if c.Code, ok = s.Attr("data-currency-code"); !ok {
|
if code, ok = s.Attr("data-currency-code"); !ok {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if c.Code, ok = codeAliases[code]; !ok {
|
||||||
|
c.Code = code
|
||||||
|
}
|
||||||
|
|
||||||
if _, exist := ret[c.Code]; exist {
|
if _, exist := ret[c.Code]; exist {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -145,7 +153,7 @@ func (m *MyCurrencyNet) Get(codes ...string) ([]*Currency, error) {
|
||||||
ret[i] = &cp
|
ret[i] = &cp
|
||||||
}
|
}
|
||||||
if len(errors) > 0 {
|
if len(errors) > 0 {
|
||||||
err = fmt.Errorf(strings.Join(errors, ", "))
|
err = fmt.Errorf("%s", strings.Join(errors, ", "))
|
||||||
}
|
}
|
||||||
return ret, err
|
return ret, err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue