Documentation ¶
Overview ¶
Package cbrates implements client for the API of Central Bank of Russia, described here: http://www.cbr.ru/development/sxml/ .
Example ¶
package main import ( "context" "fmt" "log" "github.com/itroot/cbrates" ) func main() { client, err := cbrates.NewCachedClient(log.Default()) if err != nil { log.Fatal(err) } rates, err := client.GetDailyRates(context.Background(), 2022, 5, 20) if err != nil { log.Fatal(err) } for _, valute := range rates.ValuteSeq { if valute.CharCode == "USD" { fmt.Println(valute.MustParseFloat64()) break } } }
Output: 62.4031
Index ¶
Examples ¶
Constants ¶
View Source
const (
DateFormat = "02.01.2006"
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client interface { // GetDailyRates implements a client to the http://www.cbr.ru/development/sxml/ for a single day request GetDailyRates(ctx context.Context, year int, month time.Month, day int) (*ValCurs, error) }
Client is a interface for accessing the CBR API.
func NewCachedClient ¶
NewClient creates cache wrapper and a new client for the CBR API.
type Valute ¶
type Valute struct { ID string `xml:"ID,attr"` NumCode int `xml:"NumCode"` CharCode string `xml:"CharCode"` Nominal float64 `xml:"Nominal"` Name string `xml:"Name"` Value string `xml:"Value"` }
func (*Valute) MustParseFloat64 ¶
MustParseFloat64 returns currency value in RUB in float64.
Click to show internal directories.
Click to hide internal directories.