package services import "time" type Unit string const ( Metric = Unit("Metric") Imperial = Unit("Imperial") ) type User struct { ID int64 `json:"id"` Email string `json:"email"` Username string `json:"username"` DisplayUnit Unit `json:"displayUnit"` Birthdate *time.Time `json:"birthdate"` Height *float64 `json:"height"` PasswordHash string `json:"-"` } func (u User) Merge(other User) User { nu := u if other.Email != "" { nu.Email = other.Email } if other.Username != "" { nu.Username = other.Username } if other.PasswordHash != "" { nu.PasswordHash = other.PasswordHash } if other.Birthdate != nil { nu.Birthdate = other.Birthdate } if other.Height != nil && *other.Height != 0 { nu.Height = other.Height } if other.DisplayUnit != "" { nu.DisplayUnit = other.DisplayUnit } return nu }