package vo import "strings" type Currency struct { Code string NumericCode string Fraction int Grapheme string Template string Decimal string Thousand string } type Currencies map[string]*Currency var currencies = Currencies{ "EUR": {Decimal: ".", Thousand: ",", Code: "EUR", Fraction: 2, NumericCode: "978", Grapheme: "\u20ac", Template: "$1"}, "GBP": {Decimal: ".", Thousand: ",", Code: "GBP", Fraction: 2, NumericCode: "826", Grapheme: "\u00a3", Template: "$1"}, "PLN": {Decimal: ".", Thousand: ",", Code: "PLN", Fraction: 2, NumericCode: "985", Grapheme: "z\u0142", Template: "1 $"}, "USD": {Decimal: ".", Thousand: ",", Code: "USD", Fraction: 2, NumericCode: "840", Grapheme: "$", Template: "$1"}, } func NewCurrency(code string) *Currency { return &Currency{Code: strings.ToUpper(code)} } func (c *Currency) Default() *Currency { return &Currency{Decimal: ".", Thousand: ",", Code: c.Code, Fraction: 2, Grapheme: c.Code, Template: "1$"} } func (c *Currency) Get() *Currency { if curr, ok := currencies[c.Code]; ok { return curr } return c.Default() } func (c *Currency) Equals(oc *Currency) bool { return c.Code == oc.Code }