parent
5a03b38b32
commit
90dd06676c
|
@ -15,7 +15,10 @@ import (
|
|||
)
|
||||
|
||||
var (
|
||||
updateUrl = "https://www.mycurrency.net/=US"
|
||||
updateUrl = "https://www.mycurrency.net/=US"
|
||||
codeAliases = map[string]string{
|
||||
"CNH": "CNY",
|
||||
}
|
||||
|
||||
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) {
|
||||
var (
|
||||
c Currency
|
||||
code string
|
||||
isoC iso.ISOCurrency
|
||||
ok bool
|
||||
err error
|
||||
rate string
|
||||
)
|
||||
if c.Code, ok = s.Attr("data-currency-code"); !ok {
|
||||
if code, ok = s.Attr("data-currency-code"); !ok {
|
||||
return
|
||||
}
|
||||
if c.Code, ok = codeAliases[code]; !ok {
|
||||
c.Code = code
|
||||
}
|
||||
|
||||
if _, exist := ret[c.Code]; exist {
|
||||
return
|
||||
}
|
||||
|
@ -145,7 +153,7 @@ func (m *MyCurrencyNet) Get(codes ...string) ([]*Currency, error) {
|
|||
ret[i] = &cp
|
||||
}
|
||||
if len(errors) > 0 {
|
||||
err = fmt.Errorf(strings.Join(errors, ", "))
|
||||
err = fmt.Errorf("%s", strings.Join(errors, ", "))
|
||||
}
|
||||
return ret, err
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue