OsoianMarcel / bnm-go

Go library used to get official exchange rates of National bank of Moldova

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

bnm-go

Go library used to get official exchange rates of National bank of Moldova

Build Status GoDev license

Basic example

package main

import (
    "fmt"
    "log"
    "time"

    "github.com/OsoianMarcel/bnm-go"
)

func main() {
    // Create new bnm instance
    inst := bnm.NewBnm()

    // Request today's exchange rates in romanian language
    res, err := inst.Request(bnm.NewQuery("ro", time.Now()))
    if err != nil {
        log.Fatal(err)
    }

    // Find USD exchange rate
    if rate, ok := res.FindByCode("USD"); ok {
        fmt.Printf("%s (%s): %.2f\n", rate.Name, rate.Code, rate.Value)
        // Dolar S.U.A. (USD): 18.04
    } else {
        fmt.Printf("USD not found!\n")
    }
    
    // Print all exchange rates
    fmt.Printf("\n%+v\n", res.Rates)
}

Contribute

Contributions to the package are always welcome!

License

All contents of this package are licensed under the MIT license.

About

Go library used to get official exchange rates of National bank of Moldova

License:MIT License


Languages

Language:Go 100.0%