You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
966B

  1. package arg
  2. import "fmt"
  3. // FormatCurrency types format.
  4. type FormatCurrency int
  5. // Currency format.
  6. const (
  7. CurrencyFormat FormatCurrency = iota
  8. CurrencyFormatSymbol
  9. CurrencyFormatISO
  10. CurrencyFormatNarrowSymbol
  11. )
  12. // CurrencyOption configures option.
  13. type CurrencyOption func(*Currency)
  14. // WithCurrencyFormat sets format currency.
  15. func WithCurrencyFormat(format FormatCurrency) CurrencyOption {
  16. return func(c *Currency) { c.Format = format }
  17. }
  18. // WithCurrencyISO sets ISO 4217 code currecy.
  19. func WithCurrencyISO(iso string) CurrencyOption {
  20. return func(c *Currency) { c.ISO = iso }
  21. }
  22. // Currency argument.
  23. type Currency struct {
  24. Key string
  25. Value interface{}
  26. Format FormatCurrency
  27. // ISO 3-letter ISO 4217
  28. ISO string
  29. }
  30. // String gets string from currency.
  31. func (a Currency) String() string {
  32. return fmt.Sprintf("currency key:%s, value:%v", a.Key, a.Value)
  33. }
  34. // Val gets value currency.
  35. func (a Currency) Val() interface{} {
  36. return a.Value
  37. }