https://github.com/eariasvalor/products-api-go
REST API for product management built with Go and hexagonal architecture
https://github.com/eariasvalor/products-api-go
clean-architecture crud gin go golang postgresql rest-api
Last synced: 23 days ago
JSON representation
REST API for product management built with Go and hexagonal architecture
- Host: GitHub
- URL: https://github.com/eariasvalor/products-api-go
- Owner: eariasvalor
- Created: 2026-05-20T17:12:30.000Z (about 1 month ago)
- Default Branch: main
- Last Pushed: 2026-05-20T20:40:00.000Z (about 1 month ago)
- Last Synced: 2026-05-21T01:18:45.271Z (about 1 month ago)
- Topics: clean-architecture, crud, gin, go, golang, postgresql, rest-api
- Language: Go
- Homepage:
- Size: 26.4 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# products-api-go
REST API for product management built with Go and hexagonal architecture.
## Tech Stack
- **Go** — main language
- **Gin** — HTTP framework
- **PostgreSQL** — database
- **pgx** — PostgreSQL driver
## Architecture
This project follows **hexagonal architecture** (Ports & Adapters), keeping the business logic decoupled from external dependencies.
```
internal/
├── domain/ # Core entities and business rules
├── ports/
│ ├── input/ # Interfaces exposed to the outside (use cases)
│ └── output/ # Interfaces for external dependencies (DB, etc.)
├── application/ # Use case implementations
└── adapters/
├── http/ # HTTP handlers and router (Gin)
└── postgres/ # PostgreSQL repository implementation
```
## Endpoints
| Method | Endpoint | Description |
|--------|----------|-------------|
| GET | `/products` | List all products |
| GET | `/products/:id` | Get a product by ID |
| POST | `/products` | Create a product |
| PUT | `/products/:id` | Update a product |
| DELETE | `/products/:id` | Delete a product |
## Getting Started
### Prerequisites
- Go 1.21+
- PostgreSQL 18+
### Database setup
```sql
CREATE DATABASE productos_db;
\c productos_db
CREATE TABLE products (
id SERIAL PRIMARY KEY,
name VARCHAR(100) NOT NULL,
description TEXT,
price NUMERIC(10,2) NOT NULL,
stock INTEGER NOT NULL DEFAULT 0
);
```
### Environment variables
| Variable | Default | Description |
|----------|---------|-------------|
| `DB_HOST` | `localhost` | Database host |
| `DB_PORT` | `5432` | Database port |
| `DB_USER` | `postgres` | Database user |
| `DB_PASSWORD` | `` | Database password |
| `DB_NAME` | `productos_db` | Database name |
| `SERVER_PORT` | `8080` | HTTP server port |
### Run
```bash
go run main.go
```
The server will start on `http://localhost:8080`.
## Example Request
```bash
curl -X POST http://localhost:8080/products \
-H "Content-Type: application/json" \
-d '{"name":"Chair","description":"Office chair","price":99.99,"stock":10}'
```