br

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2023 License: MIT Imports: 12 Imported by: 1

README

Golang client for exchange rate of cash currency in Russia

Go Reference Test codecov

Golang client that provides latest exchange rate of USDRUB cash in largest cities of Russia.

Example

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

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

This is a very simple app that just displays USDRUB exhange rate in Novosibirsk.

package main

import (
	"fmt"

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

func main() {
	client := br.NewClient()
	rates, err := client.Rates(br.Novosibirsk)
	if err != nil {
		panic(err)
	}
	fmt.Println(rates)
}

Console output:

{
    "currency": "USD",
    "city": "novosibirsk",
    "branches": [
        {
            "bank": "ОП № 029/0000 Филиала \"Газпромбанк\" АО",
            "subway": "Заельцовская, Гагаринская, Сибирская",
            "currency": "USD",
            "buy": 87.1,
            "sell": 91.3,
            "updated": "2023-07-03T13:00:00+03:00"
        },
        {
            "bank": "ДО № 029/1007 Филиала \"Газпромбанк\" АО",
            "subway": "Заельцовская, Берёзовая роща, Гагаринская",
            "currency": "USD",
            "buy": 87.1,
            "sell": 91.3,
            "updated": "2023-07-03T13:00:00+03:00"
        },
        {
            "bank": "ДО № 029/1003 Филиала \"Газпромбанк\" АО",
            "subway": "Берёзовая роща, Маршала Покрышкина, Золотая Нива",
            "currency": "USD",
            "buy": 87.1,
            "sell": 91.3,
            "updated": "2023-07-03T13:00:00+03:00"
        }
    ]
}

See main.go.

References

For more information check out the following links:

  • Cash currency exchange rates by Banki.ru (RU)

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// Debug mode. Default: false.
	Debug bool
)

Functions

func SetLogger

func SetLogger(logger Logger) error

SetLogger specifies the logger that the package should use.

Types

type Branch

type Branch struct {
	Bank     string    `json:"bank"`
	Subway   string    `json:"subway"`
	Currency string    `json:"currency"`
	Buy      float64   `json:"buy"`
	Sell     float64   `json:"sell"`
	Updated  time.Time `json:"updated"`
}

Bank or branch.

type Branches added in v1.1.0

type Branches struct {
	Currency Currency `json:"currency"`
	City     City     `json:"city"`
	Items    []Branch `json:"items"`
}

Banks or branches.

func (*Branches) String added in v1.1.0

func (r *Branches) String() string

String representation of cash currency exchange rates.

type ByBuySorter

type ByBuySorter []Branch

ByBuySorter implements sort.Interface based on the Buy field.

func (ByBuySorter) Len

func (b ByBuySorter) Len() int

Len, Swap and Less implement sort.Interface for ByBuySorter.

func (ByBuySorter) Less

func (b ByBuySorter) Less(i, j int) bool

func (ByBuySorter) Swap

func (b ByBuySorter) Swap(i, j int)

type BySellSorter

type BySellSorter []Branch

BySellSorter implements sort.Interface based on the Sell field.

func (BySellSorter) Len

func (s BySellSorter) Len() int

Len, Swap and Less implement sort.Interface for BySellSorter.

func (BySellSorter) Less

func (s BySellSorter) Less(i, j int) bool

func (BySellSorter) Swap

func (s BySellSorter) Swap(i, j int)

type City

type City string

City type.

const (

	// City.
	Barnaul         City = "barnaul"
	Voronezh        City = "voronezh"
	Volgograd       City = "volgograd"
	Vladivostok     City = "vladivostok"
	Ekaterinburg    City = "ekaterinburg"
	Irkutsk         City = "irkutsk"
	Izhevsk         City = "izhevsk"
	Kazan           City = "kazan~"
	Krasnodar       City = "krasnodar"
	Krasnoyarsk     City = "krasnoyarsk"
	Kaliningrad     City = "kaliningrad"
	Kirov           City = "kirov"
	Kemerovo        City = "kemerovo"
	Moscow          City = "moskva"
	Novosibirsk     City = "novosibirsk"
	NizhnyNovgorod  City = "nizhniy_novgorod"
	Omsk            City = "omsk"
	Orenburg        City = "orenburg"
	Perm            City = "perm~"
	RostovOnDon     City = "rostov-na-donu"
	SaintPetersburg City = "sankt-peterburg"
	Samara          City = "samara"
	Saratov         City = "saratov"
	Sochi           City = "krasnodarskiy_kray/sochi"
	Tyumen          City = "tyumen~"
	Tolyatti        City = "samarskaya_oblast~/tol~yatti"
	Tomsk           City = "tomsk"
	Ufa             City = "ufa"
	Khabarovsk      City = "habarovsk"
	Chelyabinsk     City = "chelyabinsk"
)

type Client

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

Client.

func NewClient

func NewClient() *Client

NewClient creates a new client.

func (*Client) Rates

func (c *Client) Rates(ct City) (*Branches, error)

Rates USDRUB by and city (Moscow, if empty).

type Currency

type Currency string

Currency type.

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.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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