Skip to content

Instantly share code, notes, and snippets.

@Develp10
Created April 15, 2022 08:50
Show Gist options
  • Select an option

  • Save Develp10/723d1c3f2006d4240dba213212dbe83f to your computer and use it in GitHub Desktop.

Select an option

Save Develp10/723d1c3f2006d4240dba213212dbe83f to your computer and use it in GitHub Desktop.
package products
import (
"go-fiber-api-docker/pkg/common/models"
"github.com/gofiber/fiber/v2"
)
func (h handler) DeleteProduct(c *fiber.Ctx) error {
id := c.Params("id")
var product models.Product
if result := h.DB.First(&product, id); result.Error != nil {
return fiber.NewError(fiber.StatusNotFound, result.Error.Error())
}
// delete product from db
h.DB.Delete(&product)
return c.SendStatus(fiber.StatusOK)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment