Documentation
¶
Overview ¶
Package format provides utility methods for formatting units.
Index ¶
Constants ¶
const ( Celsius temperatureUnit = iota Fahrenheit Kelvin )
Pass in these constants to SetTemperatureUnit to control the default format.
Variables ¶
This section is empty.
Functions ¶
func Byterate ¶
Byterate formats a Datarate in SI units using go-humanize. e.g. Byterate(10 * unit.MegabytePerSecond) == "10 MB/s"
func Bytesize ¶
Bytesize formats a Datasize in SI units using go-humanize. e.g. Bytesize(10 * unit.Megabyte) == "10 MB"
func IByterate ¶
IByterate formats a Datarate in IEC units using go-humanize. e.g. Byterate(10 * unit.MebibytePerSecond) == "10 MiB/s"
func IBytesize ¶
IBytesize formats a Datasize in IEC units using go-humanize. e.g. IBytesize(10 * unit.Mebibyte) == "10 MiB"
func SetTemperatureUnit ¶
func SetTemperatureUnit(f temperatureUnit)
SetTemperatureUnit sets the default unit used when formatting temperatures.
Types ¶
type Value ¶
type Value struct { Unit string // contains filtered or unexported fields }
Value represents a formatted Unit value.
func SI ¶
SI formats an SI unit value by scaling it to a sensible multiplier, and returns a three-character value (four if negative) and a suffix that's either empty or a single character. e.g. format.SI((20480*unit.Megabyte).Bytes(), "B") == {"20.48000", "GB"} or format.SI((0.001234*unit.Foot).Meter(), "m") == {"376.1232", "µm"}
func SIUnit ¶
SIUnit formats a unit.Unit value to an appropriately scaled base unit. For example, SIUnit(length) is equivalent to SI(length.Meters(), "m"). For non-base units (e.g. feet), use SI(length.Feet(), "ft").
func (Value) Number ¶
Number returns a representation that occupies at least `width` characters, increasing precision to fill the available space.
type Values ¶
type Values []Value
Values represents an ordered list of values, e.g. hours/minutes/seconds.
func Duration ¶
Duration formats a time.Duration by providing the two most significant units.
func Unit ¶
Unit formats a unit.Unit value to the most appropriately scaled base unit. For example, Unit(length) is equivalent to SI(length.Meters(), "m"). For non-base units (e.g. feet), use SI(length.Feet(), "ft").