currency

package
v0.0.0-...-4d895cd Latest Latest
Warning

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

Go to latest
Published: Jan 25, 2024 License: GPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	THB = Code{xcurrency.THB}
	RUB = Code{xcurrency.RUB}
	USD = Code{xcurrency.USD}
	EUR = Code{xcurrency.EUR}
)

Functions

func RegisterGeneratedResolver

func RegisterGeneratedResolver()

RegisterGeneratedResolver registers generated resolver.

Types

type Amount

type Amount struct {
	// Currency in which the price is presented
	CurrencyCode Code `json:"currency_code" swaggen:"required,type=string,format=currency"`

	// Float value of price
	Value float64 `json:"value" swaggen:"required"`
}

Currency amount.

func (Amount) Add

func (a Amount) Add(b Amount) Amount

func (Amount) IsNegative

func (a Amount) IsNegative() bool

func (Amount) Subtract

func (a Amount) Subtract(b Amount) Amount

type Code

type Code struct {
	xcurrency.Unit
}

swaggen: type=string swaggen: format=currency

func MustNewCode

func MustNewCode(code string) Code

func NewCode

func NewCode(code string) (Code, error)

NewCode constructs Code from the provided string.

func (Code) EncodeValues

func (cc Code) EncodeValues(key string, v *url.Values) error

func (*Code) FromString

func (cc *Code) FromString(str string) error

FromString sets the Code from its string representation.

func (Code) MarshalJSON

func (cc Code) MarshalJSON() ([]byte, error)

func (Code) MarshalText

func (cc Code) MarshalText() ([]byte, error)

MarshalText implements the encoding.TextMarshaler interface and serializes Code to its string representation. NOTE: zero currency code marshals as "XXX", need fix this?

func (*Code) UnmarshalJSON

func (cc *Code) UnmarshalJSON(data []byte) error

func (*Code) UnmarshalText

func (cc *Code) UnmarshalText(data []byte) error

UnmarshalText implements the encoding.TextUnmarshaler interface and parses Code from its string representation.

type FullRates

type FullRates map[Code]Rates

FullRates to convert from one currency to another. Example: 1 USD = Rates[RUB]USD * 1 = 77.374996 * 1 = 77.374996 RUB.

func (FullRates) Convert

func (rates FullRates) Convert(amount *Amount, to Code) (*Amount, error)

type Rates

type Rates map[Code]float64

func (*Rates) UnmarshalJSON

func (rates *Rates) UnmarshalJSON(data []byte) error

Jump to

Keyboard shortcuts

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