Documentation
¶
Overview ¶
Package units offers shared code for handling standard units of measurement. It takes inspiration from Golang's time library and applies similar ideas to other units of measure. This is achieved through a common declaration called a Unit, which organizes measurements in increasing order, often derived from a base unit. A Unit also facilitates parsing and formatting of measurements to improve computer use and human readability (respectively). To get a better understanding of its functioning, you can explore the provided packages for more specific information.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrValueDoesNotMatchPattern notifies the caller that the provided string text did not match our expected format. ErrValueDoesNotMatchPattern = fmt.Errorf("value does not match pattern") )
Functions ¶
This section is empty.
Types ¶
type Number ¶
type Number interface {
constraints.Signed
}
Number defines a constraint to ensure the values provided to units are integer based (i.e. we're working with whole numbers). This makes sure we're working with whole numbers and not handling fractions internally. This forces the programmer to handle all rounding and truncation.
type Option ¶
type Option interface {
Apply(*Options)
}
Option provides a mechanism to tune specific behaviors of the system such as formatting and numeric precision.
type OptionFunc ¶
type OptionFunc func(*Options)
OptionFunc provides a functional way to tune specific options of the underlying behavior.
func Format ¶
func Format(fmt byte) OptionFunc
Format configures how floating point numbers are rendered. The section below can be found in strconv.FormatFloat.
'b' (-ddddp±ddd, a binary exponent), 'e' (-d.dddde±dd, a decimal exponent), 'E' (-d.ddddE±dd, a decimal exponent), 'f' (-ddd.dddd, no exponent), 'g' ('e' for large exponents, 'f' otherwise), 'G' ('E' for large exponents, 'f' otherwise), 'x' (-0xd.ddddp±ddd, a hexadecimal fraction and binary exponent), or 'X' (-0Xd.ddddP±ddd, a hexadecimal fraction and binary exponent).
For further information, please consult the strconv documents.
func Precision ¶
func Precision(precision int) OptionFunc
Precision configures how many decimal places are used when rendering floating point numbers.
func (OptionFunc) Apply ¶
func (f OptionFunc) Apply(opts *Options)
type Options ¶
Options defines various formatting options that can be used to tailor a given Unit.Format call including which number format is used to render a floating point number and its associated precision.
type Symbol ¶
Symbol defines how various sizes should be labeled. Some values may contain multiple labels, but the preferred label that will be used when printing should come first in the list.
type Unit ¶
A Unit of measure is a standardized quantity used to quantify and express the magnitude or value of a physical quantity. It establishes a reference point or a standard against which measurements can be made and compared. Units of measure provide a consistent and universally understood way to communicate and exchange information about quantities in various domains, such as length, mass, time, temperature, volume, and many others.