Documentation ¶
Overview ¶
Package temperature provides Temperature struct and a convert method to deal with different temperature scale.
Index ¶
Examples ¶
Constants ¶
View Source
const ( //Celsius temperature unit Celsius = CelsiusUnit("°C") //Kelvin temperature unit Kelvin = KelvinUnit("K") //Fahrenheit temperature unit Fahrenheit = FahrenheitUnit("°F") //Rankine temperature unit Rankine = RankineUnit("°Ra") //Delisle temperature unit Delisle = DelisleUnit("°D") //Reaumur temperature unit Reaumur = ReaumurUnit("°Re") )
Variables ¶
View Source
var ErrNilArgument = errors.New("argument can't be nil")
ErrNilArgument is an error when the argument is nil.
Functions ¶
func Equals ¶
func Equals(a Temperature, b Temperature) bool
Equals returns true if two temperature are equals.
Types ¶
type CelsiusUnit ¶
type CelsiusUnit Unit
func (CelsiusUnit) FromKelvin ¶
func (CelsiusUnit) FromKelvin(v float64) Temperature
func (CelsiusUnit) ToKelvin ¶
func (CelsiusUnit) ToKelvin(v float64) float64
type Convertible ¶
type Convertible interface { ToKelvin(float64) float64 FromKelvin(float64) Temperature }
Convertible provides function to convert from and to Kelvin unit.
type DelisleUnit ¶
type DelisleUnit Unit
func (DelisleUnit) FromKelvin ¶
func (DelisleUnit) FromKelvin(v float64) Temperature
func (DelisleUnit) ToKelvin ¶
func (DelisleUnit) ToKelvin(v float64) float64
type FahrenheitUnit ¶
type FahrenheitUnit Unit
func (FahrenheitUnit) FromKelvin ¶
func (FahrenheitUnit) FromKelvin(v float64) Temperature
func (FahrenheitUnit) ToKelvin ¶
func (FahrenheitUnit) ToKelvin(v float64) float64
type KelvinUnit ¶
type KelvinUnit Unit
func (KelvinUnit) FromKelvin ¶
func (KelvinUnit) FromKelvin(v float64) Temperature
func (KelvinUnit) ToKelvin ¶
func (KelvinUnit) ToKelvin(v float64) float64
type RankineUnit ¶
type RankineUnit Unit
func (RankineUnit) FromKelvin ¶
func (RankineUnit) FromKelvin(v float64) Temperature
func (RankineUnit) ToKelvin ¶
func (RankineUnit) ToKelvin(v float64) float64
type ReaumurUnit ¶
type ReaumurUnit Unit
func (ReaumurUnit) FromKelvin ¶
func (ReaumurUnit) FromKelvin(v float64) Temperature
func (ReaumurUnit) ToKelvin ¶
func (ReaumurUnit) ToKelvin(v float64) float64
type Temperature ¶
type Temperature interface { Stringer Value() float64 SetValue(float64) Unit() Convertible SetUnit(Convertible) SetTemperature(Temperature) SetTemperateChangeHandler(temperatureChangeHandler) }
Temperature provides all the function needed for a temperature.
func Convert ¶
func Convert(input Temperature, output Convertible) (Temperature, error)
Convert a temperature to different unit.
Example ¶
c := New(30, Celsius) result, err := Convert(c, Fahrenheit) if err != nil { log.Fatal(err) } fmt.Println(result)
Output: 86 °F
func NewWithHandler ¶
func NewWithHandler(v float64, unit Convertible, handler temperatureChangeHandler) Temperature
NewWithHandler returns a new temperature with a handler to handle temperature changes.
Click to show internal directories.
Click to hide internal directories.