This is a sample e-commerce API built with Go and Gin framework. It provides endpoints for user authentication, product management, and order processing.
- User authentication (login, register)
- Product management (list, create, update, delete)
- Order management (create, list, update status, cancel)
- Swagger documentation
- Go 1.22
-
Clone the repository:
git clone https://github.com/cgzirim/ecommerce-api.git cd ecommerce-api -
Install dependencies:
go mod tidy
-
Set up environment variables:
Create a
.envfile in the root directory and add the necessary environment variables. Example:DB_HOST=localhost DB_PORT=5432 DB_USER=your_db_user DB_PASSWORD=your_db_password DB_NAME=ecommerce_db
-
Run the database migrations:
go run main.go migrate
-
Start the server:
go run main.go
-
The API will be available at
http://localhost:8080.
You can use Docker Compose to run the application along with the PostgreSQL database.
-
Ensure Docker and Docker Compose are installed on your machine.
-
Build and start the containers:
docker-compose up --build
-
The API will be available at
http://localhost:8080. -
The PostgreSQL database will be available at
localhost:5444.
Swagger documentation is available at http://localhost:8080/swagger/index.html.
controllers/: Contains the handler functions for the API endpoints and their tests.db/: Database connection and migration scripts.middleware/: Custom middleware functions.docs/: Swagger documentation files.