Documentation ¶
Overview ¶
Package unit implements parsing for string values with units.
Index ¶
Constants ¶
View Source
const ( // K is 1024 byte K int64 = 1 << (10 * iota) // M is 1024 K M // G is 1024 M G // T is 1024 G T // P is 1024 T P // E is 1024 P E )
Variables ¶
View Source
var DefaultUnits = map[string]int64{ "B": 1, "K": K, "M": M, "G": G, "T": T, "P": P, "E": E, "kB": 1000, "KB": 1000, "MB": 1000 * 1000, "GB": 1000 * 1000 * 1000, "TB": 1000 * 1000 * 1000 * 1000, "PB": 1000 * 1000 * 1000 * 1000 * 1000, "EB": 1000 * 1000 * 1000 * 1000 * 1000 * 1000, }
DefaultUnits is the default unit mapping as used by many standard cli-tools.
Functions ¶
This section is empty.
Types ¶
type Unit ¶
type Unit struct {
// contains filtered or unexported fields
}
Unit is a map of unit names to conversion multipliers.
There must be a unit that maps to 1.
func MustNewUnit ¶
MustNewUnit is like NewUnit but panics if the mapping 'm' is not valid.
func (*Unit) MustNewValue ¶
MustNewValue is like NewValue but panics if the new Value could not be generated.
type Value ¶
type Value struct { // value is the integer value. Value int64 // sign is the explicit sign given by the string converted to the // integer. ExplicitSign Sign // set to false if this is the default value, true if the the option was given IsSet bool // contains filtered or unexported fields }
Value is any value that can be represented by a unit.
Value implements flag.Value and flag.Getter.
Click to show internal directories.
Click to hide internal directories.