Documentation ¶
Overview ¶
Package formatter implements some functions to format string, struct.
Index ¶
- Constants
- func BinaryBytes(size float64, precision ...int) string
- func Comma(value interface{}, symbol string) string
- func DecimalBytes(size float64, precision ...int) string
- func ParseBinaryBytes(size string) (uint64, error)
- func ParseDecimalBytes(size string) (uint64, error)
- func Pretty(v interface{}) (string, error)
- func PrettyToWriter(v interface{}, out io.Writer) error
Constants ¶
const ( // Decimal UnitB = 1 UnitKB = 1000 UnitMB = 1000 * UnitKB UnitGB = 1000 * UnitMB UnitTB = 1000 * UnitGB UnitPB = 1000 * UnitTB UnitEB = 1000 * UnitPB // Binary UnitBiB = 1 UnitKiB = 1024 UnitMiB = 1024 * UnitKiB UnitGiB = 1024 * UnitMiB UnitTiB = 1024 * UnitGiB UnitPiB = 1024 * UnitTiB UnitEiB = 1024 * UnitPiB )
Variables ¶
This section is empty.
Functions ¶
func BinaryBytes ¶ added in v1.3.8
BinaryBytes returns a human-readable byte size under binary standard (base 1024) The precision parameter specifies the number of digits after the decimal point, which defaults to 4.
func Comma ¶
Comma add comma to a number value by every 3 numbers from right. ahead by symbol char. if value is invalid number string eg "aa", return empty string Comma("12345", "$") => "$12,345", Comma(12345, "$") => "$12,345"
func DecimalBytes ¶ added in v1.3.8
DecimalBytes returns a human readable byte size under decimal standard (base 1000) The precision parameter specifies the number of digits after the decimal point, which defaults to 4. Play: https://go.dev/play/p/FPXs1suwRcs
func ParseBinaryBytes ¶ added in v1.3.8
ParseBinaryBytes return the human readable bytes size string into the amount it represents(base 1024). ParseBinaryBytes("42 mib") -> 44040192, nil
func ParseDecimalBytes ¶ added in v1.3.8
ParseDecimalBytes return the human readable bytes size string into the amount it represents(base 1000). ParseDecimalBytes("42 MB") -> 42000000, nil
func PrettyToWriter ¶ added in v1.3.8
PrettyToWriter pretty encode data to writer.
Types ¶
This section is empty.