I am and application where I am trying to indicate if a client is active or not. If I manually set the ClientActive boolean to False, I can successfully convert it to True. But if it is True, it will not set to False. I am using GoFiber and Gorm
models/Client.go
type Client struct {
gorm.Model
Slug string `json:"slug" gorm:"unique"`
ClientName string `json:"client_name"`
Address string `json:"address,omitempty"`
Address2 string `json:"address_2,omitempty" gorm:"null"`
Phone string `json:"phone" gorm:"null"`
PrimaryEmail string `json:"primary_email" gorm:"null"`
SecondaryEmail string `json:"secondary_email" gorm:"null"`
ClientActive bool `json:"client_active" gorm:"default:true"`
Contacts []Contact
Devices []Device
}
handlers/clientHandler.go
func ClientUpdate(c \*fiber.Ctx) error {
slug := c.Params("slug")
var data models.Client
err := c.BodyParser(&data)
if err != nil {
return err
}
// todo: the ClientActive variable will set as true, but never false
client := &models.Client{
ClientName: data.ClientName,
Address: data.Address,
Address2: data.Address2,
Phone: data.Phone,
PrimaryEmail: data.PrimaryEmail,
SecondaryEmail: data.SecondaryEmail,
ClientActive: data.ClientActive,
}
err = database.DB.Model(&data).Where("slug = ?", slug).Updates(&client).Error
if err != nil {
return err
}
return c.JSON(client)
}
All other lines update without issue. The only problem is the ClientActive boolean.
The full code is available at https://github.com/simpleittools/assetAPI
I have confirmed that the data is being sent as a boolean. I have run a fmt.Prtintln(client) both before and after the database input and it does show correctly as false.
I am getting no errors in the process.