money

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2023 License: MIT Imports: 9 Imported by: 22

README

github.com/crediterra/money

Golang package to work with money

Documentation

Index

Constants

View Source
const (
	EUR_SIGN = "€"
	USD_SIGN = "$"
	GPB_SIGN = "£"
	JPY_SIGN = "¥"
	RUR_SIGN = "₽"
	IRR_SIGN = "﷼"
	UAH_SIGN = "₴"
	UZS_SIGN = "сўм"
	BYN_SIGN = "Br"
	TJS_SIGN = "смн."
	KZT_SIGN = "₸"
)

Variables

View Source
var CURRENCY_BYN = Currency("BYN")
View Source
var CURRENCY_EUR = Currency("EUR")
View Source
var CURRENCY_GBP = Currency("GPB")
View Source
var CURRENCY_IRR = Currency("IRR")
View Source
var CURRENCY_JPY = Currency("JPY")
View Source
var CURRENCY_KZT = Currency("KZT")
View Source
var CURRENCY_RUB = Currency("RUB")
View Source
var CURRENCY_TJS = Currency("TJS")
View Source
var CURRENCY_UAH = Currency("UAH")
View Source
var CURRENCY_USD = Currency("USD")
View Source
var CURRENCY_UZS = Currency("UZS")

Functions

func HasCurrencyPrefix

func HasCurrencyPrefix(s string) bool

Types

type Amount

type Amount struct {
	Currency Currency
	Value    decimal.Decimal64p2
}

func NewAmount

func NewAmount(currency Currency, value decimal.Decimal64p2) Amount

func (*Amount) MarshalJSON

func (mj *Amount) MarshalJSON() ([]byte, error)

func (*Amount) MarshalJSONBuf

func (mj *Amount) MarshalJSONBuf(buf fflib.EncodingBuffer) error

func (Amount) String

func (a Amount) String() string

func (*Amount) UnmarshalJSON

func (uj *Amount) UnmarshalJSON(input []byte) error

func (*Amount) UnmarshalJSONFFLexer

func (uj *Amount) UnmarshalJSONFFLexer(fs *fflib.FFLexer, state fflib.FFParseState) error

type Balance

type Balance map[Currency]decimal.Decimal64p2

func (Balance) Add

func (b Balance) Add(amount Amount) Balance

func (Balance) CommaSeparatedUnsignedWithSymbols

func (b Balance) CommaSeparatedUnsignedWithSymbols(translator interface{ Translate(s string) string }) string

func (Balance) Equal

func (b Balance) Equal(b2 Balance) bool

func (Balance) IsZero

func (b Balance) IsZero() bool

func (Balance) OnlyNegative

func (b Balance) OnlyNegative() Balance

func (Balance) OnlyPositive

func (b Balance) OnlyPositive() Balance

func (Balance) Reversed

func (b Balance) Reversed() (reversed Balance)

type Balanced

type Balanced struct {
	BalanceJson      string    `datastore:",noindex,omitempty" json:",omitempty"`
	LastTransferID   int64     `datastore:",noindex,omitempty" json:",omitempty"`
	LastTransferAt   time.Time `datastore:",noindex,omitempty"`           // `json:",omitempty"` - http://stackoverflow.com/questions/32643815/golang-json-omitempty-with-time-time-field
	CountOfTransfers int       `datastore:",omitempty" json:",omitempty"` // Do not remove, need for hiding balance/history menu in Telegram
	BalanceCount     int       `datastore:",noindex,omitempty" json:"-"`
}

ffjson: skip

func (*Balanced) AddToBalance

func (balanced *Balanced) AddToBalance(currency Currency, value decimal.Decimal64p2) (Balance, error)

func (*Balanced) Balance

func (balanced *Balanced) Balance() (balance Balance)

func (*Balanced) SetBalance

func (balanced *Balanced) SetBalance(balance Balance) error

type Currency

type Currency string

func CleanupCurrency

func CleanupCurrency(s string) Currency

func (Currency) IsMoney

func (c Currency) IsMoney() bool

func (Currency) Sign

func (c Currency) Sign() string

func (Currency) SignAndCode

func (c Currency) SignAndCode() string

type TestStruct

type TestStruct struct {
	ID   int64
	Name string
}

Jump to

Keyboard shortcuts

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