Documentation
¶
Index ¶
- Constants
- Variables
- func GetPrefixPrefixFactor(in Prefix, out Prefix) func(value interface{}) interface{}
- func GetPrefixStringPrefixStringFactor(in string, out string) func(value interface{}) interface{}
- func GetUnitUnitFactor(in Unit, out Unit) (func(value interface{}) interface{}, error)
- type Measure
- type Prefix
- type Unit
- func GetUnitPrefixFactor(in Unit, out Prefix) (func(value interface{}) interface{}, Unit)
- func GetUnitPrefixStringFactor(in Unit, out string) (func(value interface{}) interface{}, Unit)
- func GetUnitStringPrefixStringFactor(in string, out string) (func(value interface{}) interface{}, Unit)
- func NewUnit(unitStr string) Unit
Constants ¶
const ( InvalidPrefix Prefix = iota Base = 1 Yotta = 1e24 Zetta = 1e21 Exa = 1e18 Peta = 1e15 Tera = 1e12 Giga = 1e9 Mega = 1e6 Kilo = 1e3 Milli = 1e-3 Micro = 1e-6 Nano = 1e-9 Kibi = 1024 Mebi = 1024 * 1024 Gibi = 1024 * 1024 * 1024 Tebi = 1024 * 1024 * 1024 * 1024 Pebi = 1024 * 1024 * 1024 * 1024 * 1024 Exbi = 1024 * 1024 * 1024 * 1024 * 1024 * 1024 Zebi = 1024 * 1024 * 1024 * 1024 * 1024 * 1024 * 1024 Yobi = 1024 * 1024 * 1024 * 1024 * 1024 * 1024 * 1024 * 1024 )
Variables ¶
var INVALID_UNIT = NewUnit("foobar")
Functions ¶
func GetPrefixPrefixFactor ¶
GetPrefixPrefixFactor creates the default conversion function between two prefixes. It returns a conversation function for the value.
func GetPrefixStringPrefixStringFactor ¶
GetPrefixStringPrefixStringFactor is a wrapper for GetPrefixPrefixFactor with string inputs instead of prefixes. It also returns a conversation function for the value.
func GetUnitUnitFactor ¶
GetUnitUnitFactor gets the conversion function and (maybe) error for unit to unit conversion. It is basically a wrapper for GetPrefixPrefixFactor with some special cases for temperature conversion between Fahrenheit and Celsius.
Types ¶
type Measure ¶
type Measure int
func NewMeasure ¶
NewMeasure creates a new measure out of a string representing a measure like 'Bytes', 'Flops' and 'precent'. It uses regular expressions for matching.
type Prefix ¶
type Prefix float64
func NewPrefix ¶
NewPrefix creates a new prefix out of a string representing a unit like 'k', 'K', 'M' or 'G'.
type Unit ¶
type Unit interface {
Valid() bool
String() string
Short() string
AddUnitDenominator(div Measure)
// contains filtered or unexported methods
}
func GetUnitPrefixFactor ¶
GetUnitPrefixFactor gets the conversion function and resulting unit for a unit and a prefix. This is the most common case where you have some input unit and want to convert it to the same unit but with a different prefix. The returned unit represents the value after conversation.
func GetUnitPrefixStringFactor ¶
GetUnitPrefixStringFactor gets the conversion function and resulting unit for a unit and a prefix as string. It is a wrapper for GetUnitPrefixFactor
func GetUnitStringPrefixStringFactor ¶
func GetUnitStringPrefixStringFactor(in string, out string) (func(value interface{}) interface{}, Unit)
GetUnitStringPrefixStringFactor gets the conversion function and resulting unit for a unit and a prefix when both are only string representations. This is just a wrapper for GetUnitPrefixFactor with the given input unit and the desired output prefix.