formatter

package
v1.4.3 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package formatter implements some functions to format string, struct.

Index

Constants

View Source
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
)

http://en.wikipedia.org/wiki/Binary_prefix

Variables

This section is empty.

Functions

func BinaryBytes added in v1.3.8

func BinaryBytes(size float64, precision ...int) string

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

func Comma(value interface{}, symbol string) string

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

func DecimalBytes(size float64, precision ...int) string

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

func ParseBinaryBytes(size string) (uint64, error)

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

func ParseDecimalBytes(size string) (uint64, error)

ParseDecimalBytes return the human readable bytes size string into the amount it represents(base 1000). ParseDecimalBytes("42 MB") -> 42000000, nil

func Pretty added in v1.3.8

func Pretty(v interface{}) (string, error)

Pretty data to JSON string.

func PrettyToWriter added in v1.3.8

func PrettyToWriter(v interface{}, out io.Writer) error

PrettyToWriter pretty encode data to writer.

Types

This section is empty.

Jump to

Keyboard shortcuts

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