yanndr / temperature

Go lib for temperature conversion

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

temperature

Build Status Go Report Card GoDoc

This is Go library for temperature conversion. So far, it allows you to convert Kelvin, Celsius, Fahrenheit, Rankine, Reaumur and Delisle unit. You can also use your own unit as long at the unit is implementing the interfaces ToKelvin and FromKelvin.

Installing

go get github.com/yanndr/temperature

Usage

c := temperature.New(30,Celsius)

result,_ := temperature.Convert(c, temperature.Fahrenheit)


fmt.Println(result)
// output 86 °F

If you want to use a unit that I didn't implement:

type newUnit temperature.Unit

const myUnit = newUnit("Y")

func (newUnit) ToKelvin(v float64) float64 {
	return v + 710
}

func (newUnit) FromKelvin(v float64) temperature.Temperature {
	return temperature.New(v-710, myUnit)
}

func main() {
	c := temperature.New(0,temperature.Celsius)

	result,_ := temperature.Convert(c, myUnit)
	fmt.Println(c)
	fmt.Println(result)
}

About

Go lib for temperature conversion

License:MIT License


Languages

Language:Go 99.4%Language:Makefile 0.6%