Convert units in Go with Pint's English definition files and conversion rules. Magnitudes are float64. No CGO and no extra modules; the defs are embedded.
You parse a string and convert it. Complete suggests unit names if you need a picker.
go get github.com/dendrascience/pint-goureg, err := pint.NewRegistry() // default_en.txt + constants_en.txt
q, err := ureg.Parse("3.2 kPa")
q2, err := q.To("mbar")
ok, err := ureg.Compatible("degC", "degF")
c, err := ureg.Converter("degC", "degF")
f, err := c.Convert(20) // 68
err = c.ConvertN(dst, src) // many samples, one converter
d, err := ureg.Converter("delta_degC", "delta_degF")
un, err := ureg.ParseUnitName("degC") // degree_Celsius
res := ureg.Complete("kilopa", 20) // includes kilopascalAfter NewRegistry, convert from many goroutines. Don't call Define or Load while converting.
For a slice of values, build a Converter and call ConvertN. Parse the unit pair once. ParseUnitName canonicalizes what you store (degC becomes degree_Celsius). Complete returns full expressions for a typeahead (kilopa → kilopascal). JSON field names on those types are part of the API. syncpint leaves that code alone.
20 degC → degF = 68 (absolute)
5 delta_degC → delta_degF = 9 (interval)
Pint adds delta_* companions for offset units (degC, degF). This package does too. The definition files also include dB, octave, contexts, and systems.
go run ./examples/demo # walkthrough
go run ./examples/convert 20degC degF # pint-convert analog
go run ./examples/bench # ConvertN throughput
go run ./examples/complete 'kilopa' # autocomplete JSONMore in examples/README.md.
Pint's default_en.txt and constants_en.txt live in this tree. The source SHA is in PINT_SHA (now 6fc0533, Pint ~0.26).
go run ./tools/syncpint --pint /path/to/pintRun that to copy the two definition files, rebuild testdata/inventory.yml, and print tests that appeared or dropped. Bump the SHA, run syncpint, then fix the parser until the ported tests pass. Apps that import this module don't need a Pint git submodule.
testdata/inventory.yml marks each Pint test_* as ported or skipped with a reason. go test ./tools/syncpint fails if a sibling checkout (or PINT_DIR) has tests missing from that list. Skipped suites (NumPy, Dask, Matplotlib) show up by name. Three compound log-arithmetic cases match Pint's own xfails.
BSD-3-Clause. Definition files keep the Pint copyright; see LICENSE and LICENSE.pint.
