Documentation ¶
Index ¶
- Variables
- func EnglishFloatFormat(precision int) float.FormatDef
- func Format(value any, config *FormatConfig) string
- func FormatValue(val reflect.Value, config *FormatConfig) string
- func GermanFloatFormat(precision int) float.FormatDef
- func Scan(dest reflect.Value, source string, config *ScanConfig) (err error)
- type FormatConfig
- type Formatter
- type FormatterFunc
- type MoneyFormat
- type ScanConfig
- type Scannable
- type Scanner
- type ScannerFunc
Constants ¶
This section is empty.
Variables ¶
View Source
var DefaultScanConfig = NewScanConfig()
Functions ¶
func EnglishFloatFormat ¶
func Format ¶
func Format(value any, config *FormatConfig) string
Format the passed value following the format config. If the value implements encoding.TextMarshaler and MarshalText does not return an error, then this string is returned instead of more generic type conversions.
func FormatValue ¶
func FormatValue(val reflect.Value, config *FormatConfig) string
FormatValue formats the passed reflect.Value following the format config. If the value implements encoding.TextMarshaler and MarshalText does not return an error, then this string is returned instead of more generic type conversions.
func GermanFloatFormat ¶
Types ¶
type FormatConfig ¶
type FormatConfig struct { Float float.FormatDef MoneyAmount MoneyFormat Percent float.FormatDef Time string Date string Nil string // Also used for nullable.Nullable and Zeroable True string False string TypeFormatters map[reflect.Type]Formatter }
func NewEnglishFormatConfig ¶
func NewEnglishFormatConfig() *FormatConfig
func NewFormatConfig ¶
func NewFormatConfig() *FormatConfig
func NewGermanFormatConfig ¶
func NewGermanFormatConfig() *FormatConfig
type Formatter ¶
type Formatter interface {
FormatValue(val reflect.Value, config *FormatConfig) string
}
type FormatterFunc ¶
type FormatterFunc func(val reflect.Value, config *FormatConfig) string
func (FormatterFunc) FormatValue ¶
func (f FormatterFunc) FormatValue(val reflect.Value, config *FormatConfig) string
type MoneyFormat ¶
func EnglishMoneyFormat ¶
func EnglishMoneyFormat(currencyFirst bool) MoneyFormat
func GermanMoneyFormat ¶
func GermanMoneyFormat(currencyFirst bool) MoneyFormat
func (*MoneyFormat) FormatAmount ¶
func (format *MoneyFormat) FormatAmount(amount money.Amount) string
func (*MoneyFormat) FormatCurrencyAmount ¶
func (format *MoneyFormat) FormatCurrencyAmount(currencyAmount money.CurrencyAmount) string
type ScanConfig ¶
type ScanConfig struct { TrueStrings []string `json:"trueStrings"` FalseStrings []string `json:"falseStrings"` NilStrings []string `json:"nilStrings"` TimeFormats []string `json:"timeFormats"` AcceptedMoneyAmountDecimals []int `json:"acceptedMoneyAmountDecimals,omitempty"` TypeScanners map[reflect.Type]Scanner `json:"-"` // Use nil to disable validation ValidateFunc func(any) error `json:"-"` }
func NewScanConfig ¶
func NewScanConfig() *ScanConfig
func (*ScanConfig) IsFalse ¶
func (c *ScanConfig) IsFalse(str string) bool
func (*ScanConfig) IsNil ¶
func (c *ScanConfig) IsNil(str string) bool
func (*ScanConfig) IsTrue ¶
func (c *ScanConfig) IsTrue(str string) bool
func (*ScanConfig) SetTypeScanner ¶
func (c *ScanConfig) SetTypeScanner(t reflect.Type, s Scanner)
type Scannable ¶
type Scannable interface { // ScanString tries to parse and assign the passed // source string as value of the implementing type. // // If validate is true, the source string is checked // for validity before it is assigned to the type. // // If validate is false and the source string // can still be assigned in some non-normalized way // it will be assigned without returning an error. ScanString(source string, validate bool) error }
type Scanner ¶
type Scanner interface {
ScanString(dest reflect.Value, str string, config *ScanConfig) error
}
type ScannerFunc ¶
type ScannerFunc func(dest reflect.Value, str string, config *ScanConfig) error
func (ScannerFunc) ScanString ¶
func (f ScannerFunc) ScanString(dest reflect.Value, str string, config *ScanConfig) error
Click to show internal directories.
Click to hide internal directories.