strfmt

package
v0.0.0-...-f3f6071 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 30, 2024 License: MIT Imports: 13 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultScanConfig = NewScanConfig()

Functions

func EnglishFloatFormat

func EnglishFloatFormat(precision int) float.FormatDef

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

func GermanFloatFormat(precision int) float.FormatDef

func Scan

func Scan(dest reflect.Value, source string, config *ScanConfig) (err error)

Scan source into dest using the given ScanConfig. If dest is an assignable nil pointer variable, then a new object of the pointed to type will be allocated and set.

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

type MoneyFormat struct {
	CurrencyFirst bool
	ThousandsSep  rune
	DecimalSep    rune
	Precision     int
}

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) ParseTime

func (c *ScanConfig) ParseTime(str string) (t time.Time, ok 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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL