src

Go monorepo.
git clone git://code.dwrz.net/src
Log | Files | Refs

user.go (828B)


      1 package user
      2 
      3 import (
      4 	"fmt"
      5 	"time"
      6 
      7 	"code.dwrz.net/src/pkg/dqs/diet"
      8 	"code.dwrz.net/src/pkg/dqs/user/units"
      9 )
     10 
     11 type User struct {
     12 	Birthday     time.Time    `json:"birthday"`
     13 	BodyFat      float64      `json:"bodyFat"`
     14 	Diet         diet.Diet    `json:"diet"`
     15 	Height       float64      `json:"height"`
     16 	Name         string       `json:"name"`
     17 	TargetWeight float64      `json:"targetWeight"`
     18 	Units        units.System `json:"units"`
     19 	Weight       float64      `json:"weight"`
     20 }
     21 
     22 var DefaultUser = User{
     23 	Diet:  diet.Vegetarian,
     24 	Units: units.Metric,
     25 }
     26 
     27 func (u *User) SetDiet(d diet.Diet) error {
     28 	switch d {
     29 	case diet.Omnivore:
     30 		u.Diet = diet.Omnivore
     31 	case diet.Vegan:
     32 		u.Diet = diet.Vegan
     33 	case diet.Vegetarian:
     34 		u.Diet = diet.Vegetarian
     35 	default:
     36 		return fmt.Errorf("unrecognized diet: %s", d)
     37 	}
     38 
     39 	return nil
     40 }