Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/yanndr/temperature
Go lib for temperature conversion
https://github.com/yanndr/temperature
conversion converter go golang scale temperature temperature-conversion temperature-converter
Last synced: 5 days ago
JSON representation
Go lib for temperature conversion
- Host: GitHub
- URL: https://github.com/yanndr/temperature
- Owner: yanndr
- License: mit
- Created: 2017-07-17T17:38:48.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-03-26T23:44:07.000Z (over 6 years ago)
- Last Synced: 2024-06-20T19:24:34.254Z (5 months ago)
- Topics: conversion, converter, go, golang, scale, temperature, temperature-conversion, temperature-converter
- Language: Go
- Size: 49.8 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# temperature
[![Build Status](https://travis-ci.org/yanndr/temperature.svg?branch=master)](https://travis-ci.org/yanndr/temperature) [![Go Report Card](https://goreportcard.com/badge/github.com/yanndr/temperature)](https://goreportcard.com/report/github.com/yanndr/temperature)
[![GoDoc](https://godoc.org/github.com/yanndr/temperature?status.svg)](https://godoc.org/github.com/yanndr/temperature)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.Unitconst 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)
}```