You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
quartermaster/internal/utils/utils.go

28 lines
519 B

package utils
import (
"github.com/dustinpianalto/errors"
"github.com/dustinpianalto/quartermaster"
)
func UnitFromString(s string) (quartermaster.Unit, error) {
switch s {
case "Teaspoon":
return 0, nil
case "Tablespoon":
return 1, nil
case "Cup":
return 2, nil
case "Ounce":
return 3, nil
case "Gram":
return 4, nil
case "Pound":
return 5, nil
case "Individual":
return 6, nil
default:
return -1, errors.E(errors.Method("utils/UnitFromString"), errors.Malformed, "not a valid unit")
}
}