exchange

package
v0.0.0-...-c53f600 Latest Latest
Warning

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

Go to latest
Published: May 19, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	USD = "USD"
)

Variables

View Source
var (
	API_URL            = "https://api.privatbank.ua/p24api/pubinfo?exchange&coursid=11"
	ErrUSDRateNotFound = errors.New("USD rate not found")
)
View Source
var FetchRate = func() (float64, error) {
	resp, err := http.Get(API_URL)
	if err != nil {
		return 0, fmt.Errorf("failed to make GET request: %w", err)
	}
	if resp.StatusCode != http.StatusOK {
		return 0, fmt.Errorf("received non-200 response code: %d", resp.StatusCode)
	}
	defer resp.Body.Close()

	body, err := io.ReadAll(resp.Body)
	if err != nil {
		return 0, fmt.Errorf("failed to read response body: %w", err)
	}

	return parseRates(body)
}

Functions

This section is empty.

Types

type Rate

type Rate struct {
	Ccy     string `json:"ccy"`
	BaseCcy string `json:"base_ccy"`
	Buy     string `json:"buy"`
	Sale    string `json:"sale"`
}

Jump to

Keyboard shortcuts

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