utils

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2021 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// UpArrow provides the symbol for increase
	UpArrow = "▲"
	// DownArrow provides the symbol for decrease
	DownArrow = "▼"
)

Variables

This section is empty.

Functions

func GetCurrencyID added in v1.0.1

func GetCurrencyID() string

GetCurrencyID returns the currencyID stored from metadata

func GetFavourites

func GetFavourites() map[string]bool

GetFavourites reads stored favourite coin details from ~/.cryptgo-data.json and returns a map.

func GetPortfolio

func GetPortfolio() map[string]float64

GetPortfolio reads stored portfolio details from ~/.cryptgo-data.json and returns a map.

func LoopTick

func LoopTick(ctx context.Context, t time.Duration, action func(errChan chan error)) error

LoopTick runs a given action in a loop in periods of 't' duration. It exits when the context is cancelled

func MaxFloat64

func MaxFloat64(a ...float64) float64

MaxFloat64 returns maximum float from a given number of floats

func MinFloat64

func MinFloat64(a ...float64) float64

MinFloat64 returns minimum float from a given number of floats

func RoundValues

func RoundValues(num1, num2 float64) ([]float64, string)

RoundValues rounds off a pair of given floats to Thousands (kilo), Millions (mega) or Billions (giga).

func SaveMetadata

func SaveMetadata(favourites map[string]bool, currency string, portfolio map[string]float64) error

SaveMetadata exports favourites, currency and portfolio to disk. Data is saved on ~/.cryptgo-data.json

func SortData

func SortData(data [][]string, sortIdx int, sortAsc bool, sortCase string)

SortData helps sort table rows. It sorts the table based on values given in the sortIdx column and sorts ascending if sortAsc is true. sortCase is set to identify the set of 'less' functions to use to sort the selected column by.

Types

type AllCurrencyData

type AllCurrencyData struct {
	Data      []Currency `json:"data"`
	Timestamp uint       `json:"timestamp"`
}

AllCurrencyData holds data of a group of currencies fetched from CoinCap

type Currency

type Currency struct {
	ID             string `json:"id"`
	Symbol         string `json:"symbol"`
	CurrencySymbol string `json:"currencySymbol"`
	Type           string `json:"type"`
	RateUSD        string `json:"rateUsd"`
}

Currency holds currency data when fetched from CoinCap

type Metadata

type Metadata struct {
	Favourites map[string]bool    `json:"favourites"`
	Currency   string             `json:"currency"`
	Portfolio  map[string]float64 `json:"portfolio"`
}

Metadata holds persistent information to be stored to disk

Jump to

Keyboard shortcuts

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