blob: c66e94dffb3ca9c1127ed25282606d5ed4e6a747 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
package mass
import (
"errors"
"fmt"
)
type Mass float32
const (
Gram Mass = 1
Kilogram Mass = 1_000
Pound Mass = 453.5924
)
type FlowRate float32
const (
KilogramPerSecond FlowRate = 1
PoundPerMinute FlowRate = 0.007_559_872_833
)
func FlowRateUnitFromString(s string) (FlowRate, error) {
// Each case corresponds to a value in FlowRateUnitStrings().
switch s {
case "kg/s":
return KilogramPerSecond, nil
case "lb/min":
return PoundPerMinute, nil
default:
return *new(FlowRate), errors.New(
fmt.Sprintf("invalid mass flow rate unit: '%s'", s))
}
}
|