cbr

package module
v1.0.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 10, 2023 License: MIT Imports: 13 Imported by: 1

README

Golang client for the Central Bank of the Russian Federation currency rates API

Go Reference Test Codecov

go-cbr-client is a fork of matperez's client for CBRF API.

Example

First, ensure the library is installed and up to date by running

go get -u github.com/ivanglie/go-cbr-client

This is a very simple app that just displays exhange rate of US dollar.

package main

import (
	"fmt"
	"time"

	cbr "github.com/ivanglie/go-cbr-client"
)

func main() {
	client := cbr.NewClient()
	rate, err := client.GetRate("USD", time.Now())
	if err != nil {
		panic(err)
	}
	fmt.Println(rate)
}

Console output:

76.8207

See main.go.

References

For more information check out the following links:

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Debug = false

Debug mode. If this variable is set to true, debug mode activated for the package.

Functions

func SetLogger

func SetLogger(logger Logger) error

SetLogger specifies the logger that the package should use.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is a rates service client.

func NewClient

func NewClient() *Client

NewClient creates a new rates service instance.

func (*Client) GetRate

func (s *Client) GetRate(currency string, t time.Time) (float64, error)

GetRate returns a currency rate for a given currency and date.

type Currency

type Currency struct {
	ID       string `xml:"ID,attr"`
	NumCode  uint   `xml:"NumCode"`
	CharCode string `xml:"CharCode"`
	Nom      uint   `xml:"Nominal"`
	Name     string `xml:"Name"`
	Value    string `xml:"Value"`
}

Currency is a currency item.

type Logger

type Logger interface {
	Println(v ...interface{})
	Printf(format string, v ...interface{})
}

Logger is an interface that represents the required methods to log data.

type Result

type Result struct {
	XMLName    xml.Name   `xml:"ValCurs"`
	Date       string     `xml:"Date,attr"`
	Currencies []Currency `xml:"Valute"`
}

Result is a result representation.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL