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
}
如果您发送user_account对象而未将睡眠值设置为true,则该值将自动为false我需要知道该值是否实际设置为false或者是否为false因为它还没有设置
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)
}
答案 0 :(得分:6)
对于Sleep
字段,您可以使用指针,也可以是nil:
type userAccount struct {
Sleep *bool
}
现在你可以检查一下:
func check(u userAccount) {
if u.Sleep == nil {
// not set
} else if !(*u.Sleep) {
// set to false
} else {
// set to true
}
}