This commit is contained in:
19
arg/arg.go
Normal file
19
arg/arg.go
Normal file
@@ -0,0 +1,19 @@
|
||||
package arg
|
||||
|
||||
import "fmt"
|
||||
|
||||
// Arg defaults argument.
|
||||
type Arg struct {
|
||||
Key string
|
||||
Value interface{}
|
||||
}
|
||||
|
||||
// String arg to string.
|
||||
func (a Arg) String() string {
|
||||
return fmt.Sprintf("key:%s, value:%v", a.Key, a.Value)
|
||||
}
|
||||
|
||||
// Val gets valuet argument.
|
||||
func (a Arg) Val() interface{} {
|
||||
return a.Value
|
||||
}
|
||||
45
arg/currency.go
Normal file
45
arg/currency.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package arg
|
||||
|
||||
import "fmt"
|
||||
|
||||
// FormatCurrency types format.
|
||||
type FormatCurrency int
|
||||
|
||||
// Currency format.
|
||||
const (
|
||||
CurrencyFormatSymbol FormatCurrency = iota + 1
|
||||
CurrencyFormatISO
|
||||
CurrencyFormatNarrowSymbol
|
||||
)
|
||||
|
||||
// CurrencyOption configures option.
|
||||
type CurrencyOption func(*Currency)
|
||||
|
||||
// WithCurrencyFormat sets format currency.
|
||||
func WithCurrencyFormat(format FormatCurrency) CurrencyOption {
|
||||
return func(c *Currency) { c.Format = format }
|
||||
}
|
||||
|
||||
// WithCurrencyISO sets ISO 4217 code currecy.
|
||||
func WithCurrencyISO(iso string) CurrencyOption {
|
||||
return func(c *Currency) { c.ISO = iso }
|
||||
}
|
||||
|
||||
// Currency argument.
|
||||
type Currency struct {
|
||||
Key string
|
||||
Value interface{}
|
||||
Format FormatCurrency
|
||||
// ISO 3-letter ISO 4217
|
||||
ISO string
|
||||
}
|
||||
|
||||
// String gets string from currency.
|
||||
func (a Currency) String() string {
|
||||
return fmt.Sprintf("currency key:%s, value:%v", a.Key, a.Value)
|
||||
}
|
||||
|
||||
// Val gets value currency.
|
||||
func (a Currency) Val() interface{} {
|
||||
return a.Value
|
||||
}
|
||||
49
arg/number.go
Normal file
49
arg/number.go
Normal file
@@ -0,0 +1,49 @@
|
||||
package arg
|
||||
|
||||
import "fmt"
|
||||
|
||||
// FormatNumber format number.
|
||||
type FormatNumber int
|
||||
|
||||
// format argument.
|
||||
const (
|
||||
NumberFormatDecimal FormatNumber = iota + 1
|
||||
NumberFormatPercent
|
||||
NumberFormatPerMille
|
||||
NumberFormatEngineering
|
||||
NumberFormatScientific
|
||||
)
|
||||
|
||||
// NumberOption configure number argument.
|
||||
type NumberOption func(*Number)
|
||||
|
||||
// WithNumberFormat sets format number.
|
||||
func WithNumberFormat(format FormatNumber) NumberOption {
|
||||
return func(n *Number) { n.Format = format }
|
||||
}
|
||||
|
||||
// Number argument.
|
||||
type Number struct {
|
||||
Key string
|
||||
Value interface{}
|
||||
Format FormatNumber
|
||||
}
|
||||
|
||||
// Configure number.
|
||||
func (n Number) Configure(opts ...NumberOption) Number {
|
||||
for _, o := range opts {
|
||||
o(&n)
|
||||
}
|
||||
|
||||
return n
|
||||
}
|
||||
|
||||
// Val gets number value.
|
||||
func (n Number) Val() interface{} {
|
||||
return n.Value
|
||||
}
|
||||
|
||||
// String number to string.
|
||||
func (n Number) String() string {
|
||||
return fmt.Sprintf("number key: %s, value: %v", n.Key, n.Value)
|
||||
}
|
||||
Reference in New Issue
Block a user