type user_account struct {
ID string `sql:"type:uuid;default:uuid_generate_v4()"`
Gender_Identity_id string `sql:"type:uuid;default:uuid_generate_v4()"`
Email string
Name string
LastName string
Password string
BirthDate string `sql:"type:date;default:current_time"`
AssignedSex bool
Show bool
Sleep bool
Disabled bool
}
If you send a user_account object without setting the sleep value to true , the value will be false automatically i need to know if the value was actualy set as false or if its false Because it hasn't been set
func UpdateUser(userUpdate user_account) {
db, err := gorm.Open("postgres", "user=postgres password=06maneco dbname=HookTest sslmode=disable")
var user user_account
if err != nil {
fmt.Println(err)
} else {
db.Where("id = ?", userUpdate.ID).First(&user)
if userUpdate.Name != user.Name {
user.Name = userUpdate.Name
} else if userUpdate.Password != "" {
user.Password = userUpdate.Password
} else if userUpdate.Gender_Identity_id != "" {
user.Gender_Identity_id = userUpdate.Gender_Identity_id
} else if userUpdate.Email != "" {
user.Email = userUpdate.Email
} else if userUpdate.Show != user.Show {
user.Show = userUpdate.Show
}
db.Save(&user)
}
For the Sleep
field you can use a pointer which can be also a nil:
type userAccount struct {
Sleep *bool
}
Now you can check it:
func check(u userAccount) {
if u.Sleep == nil {
// not set
} else if !(*u.Sleep) {
// set to false
} else {
// set to true
}
}
Check it in the Playground: https://play.golang.org/p/8EIs_yIC0mw.