Skip to content

Instantly share code, notes, and snippets.

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")
package products
import (
"go-fiber-api-docker/pkg/common/models"
"github.com/gofiber/fiber/v2"
)
func (h handler) GetProducts(c *fiber.Ctx) error {
var products []models.Product
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")
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")
package products
import (
"go-fiber-api-docker/pkg/common/models"
"github.com/gofiber/fiber/v2"
)
type AddProductRequestBody struct {
package products
import (
"gorm.io/gorm"
)
type handler struct {
DB *gorm.DB
}
package db
import (
"fmt"
"log"
"go-fiber-api-docker/pkg/common/config"
"go-fiber-api-docker/pkg/common/models"
"gorm.io/driver/postgres"
package models
type Product struct {
Id int `json:"id" gorm:"primaryKey"`
Name string `json:"name"`
Stock int32 `json:"stock"`
Price int32 `json:"price"`
}
package config
import (
"github.com/spf13/viper"
)
type Config struct {
Port string `mapstructure:"PORT"`
DBHost string `mapstructure:"DB_HOST"`
DBUser string `mapstructure:"DB_USER"`