Categorygithub.com/shayja/go-template-api
modulepackage
1.0.5
Repository: https://github.com/shayja/go-template-api.git
Documentation: pkg.go.dev

# README

go-template-api

Authors

Description

A Starter Template API CRUD project using Go, Gin and PostgreSQL.

To start the project, open Terminal: go run main.go

Database:

  1. Create a new Postgres DB, choose "shop" as database name, create a new user "appuser" and set a login password.
  2. Exceute the sql script from project path /scripts on "shop" database.
  3. Set your DB credentials in .env file.
  4. Add new .env file in project root with this content, change the password configuration value:

Database settings:

DB_HOST="localhost" DB_USER="appuser" DB_PASSWORD="<YOUR_PASSWORD>" DB_NAME="shop" DB_PORT=5432

App endpoints:

GET /api/v1/product

Get all products with paging

example req: curl --location 'http://localhost:8080/api/v1/product?page=1'
--data ''

GET /api/v1/product/:id

Get a product by id

example: curl --location 'http://localhost:8080/api/v1/product/3954d2d4-94cf-44f8-a237-fa905773cffd'
--data ''

POST /api/v1/product

Create a new product

example: curl --location 'http://localhost:8080/api/v1/product'
--header 'Content-Type: application/json'
--data '{"name": "Iphone 15","description": "The latest iphone from Apple", "image": "ihone.png","price": 89.99, "sku": "AABBCC2233"}'

PUT /api/v1/product/:id

Update an existing product by id

example: curl --location --request PUT 'http://localhost:8080/api/v1/product/3954d2d4-94cf-44f8-a237-fa905773cffd'
--header 'Content-Type: application/json'
--data '{"name": "Samsung Galaxy S22","description": "The latest phone from Samsung", "image": "samsung.png","price": 88.99, "sku": "XXYYZZ2233"}'

PATCH /api/v1/product/:id

Update product price by id

curl --location --request PATCH 'http://localhost:8080/api/v1/product/3954d2d4-94cf-44f8-a237-fa905773cffd'
--header 'Content-Type: application/json'
--data '{"price": 1189.99}'

DELETE /api/v1/product/:id

Delete an existing product by id

example: curl --location --request DELETE 'http://localhost:8080/api/v1/product/5'
--header 'Content-Type: application/json'
--data ''

# Packages

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author