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)) } }