# README
Golang client for the Central Bank of the Russian Federation currency rates API
go-cbr-client is a fork of matperez's client and ivangile's client for CBRF API.
Request cache and different output types added.
Example
First, ensure the library is installed and up to date by running go get -u github.com/alexanderkmd/go-cbr-client
.
This is a very simple app that just displays exchange rate of US dollar.
package main
import (
"fmt"
"time"
cbr "github.com/alexanderkmd/go-cbr-client"
)
func main() {
client := cbr.NewClient()
// For float64 value:
rateFloat64, err := client.GetRate("USD", time.Now())
// For Decimal value:
rateDecimal, err := client.GetRateDecimal("USD", time.Now())
// For String value with dot as decimal separator:
rateString, err := client.GetRateString("USD", time.Now())
if err != nil {
panic(err)
}
fmt.Println(rateFloat64)
}
See main.go.
Set Alternative API point
Due to lots of IP bans from CBR (HTTP error 403) - you can change the different/alternative compatible API URL.
For example:: www.cbr-xml-daily.ru provide one.
package main
import (
"fmt"
"time"
cbr "github.com/alexanderkmd/go-cbr-client"
)
func main() {
client := cbr.NewClient()
client.SetBaseUrl("http://new-base-url.com")
// For float64 value:
rateFloat64, err := client.GetRate("USD", time.Now())
if err != nil {
panic(err)
}
fmt.Println(rateFloat64)
}
References
For more information check out the following links: