Skip to content

Instantly share code, notes, and snippets.

@Develp10
Created April 15, 2022 09:08
Show Gist options
  • Save Develp10/72f6f9eb2611871fbb748505dc73e72f to your computer and use it in GitHub Desktop.
Save Develp10/72f6f9eb2611871fbb748505dc73e72f 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) GetProduct(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())
}
return c.Status(fiber.StatusOK).JSON(&product)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment