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.

51 lines
930B

  1. package arg
  2. import "fmt"
  3. // FormatNumber format number.
  4. type FormatNumber int
  5. // format argument.
  6. const (
  7. NumberFormatUndefined FormatNumber = iota
  8. NumberFormatDecimal
  9. NumberFormatPercent
  10. NumberFormatPerMille
  11. NumberFormatEngineering
  12. NumberFormatScientific
  13. )
  14. // NumberOption configure number argument.
  15. type NumberOption func(*Number)
  16. // WithNumberFormat sets format number.
  17. func WithNumberFormat(format FormatNumber) NumberOption {
  18. return func(n *Number) { n.Format = format }
  19. }
  20. // Number argument.
  21. type Number struct {
  22. Key string
  23. Value interface{}
  24. Format FormatNumber
  25. }
  26. // Configure number.
  27. func (n Number) Configure(opts ...NumberOption) Number {
  28. for _, o := range opts {
  29. o(&n)
  30. }
  31. return n
  32. }
  33. // Val gets number value.
  34. func (n Number) Val() interface{} {
  35. return n.Value
  36. }
  37. // String number to string.
  38. func (n Number) String() string {
  39. return fmt.Sprintf("number key: %s, value: %v", n.Key, n.Value)
  40. }