This project is an API for product management developed in Go using the Gin framework. The architecture is modular, ensuring better organization and maintainability.
Make sure you have installed:
- Golang: Install Golang
- Docker: Install Docker
-
Clone the project and navigate to the folder:
git clone https://github.com/usuario/api-go.git cd api-go
-
Configure the database connection: Edit the settings in the
db/conn.go
file to reflect your credentials. -
Start the services with Docker:
docker-compose up
-
Access the API at the address:
http://localhost:8000
The structure is organized as follows:
API-GO/
├── cmd/
│ └── main.go # Main file to start the application
├── controller/
│ └── product_controller.go # Controllers responsible for the routes
├── db/
│ └── conn.go # Database configuration and connection
├── model/
│ ├── product.go # Product model
│ └── response.go # Response structures for the API
├── repository/
│ └── product_repository.go # Layer for interacting with the database
├── usecase/
│ └── product_usecase.go # Business logic and application logic
├── .gitignore # Files ignored in version control
├── docker-compose.yml # Docker Compose configuration
├── Dockerfile # Docker container configuration
├── go.mod # Project dependencies
├── go.sum # Dependency hashes
└── README.md # Project documentation
- GET
/ping
- Returns a test message.
- Response:
{ "message": "initial tests" }
-
GET
/products
- Lists all registered products.
- Example Response:
[ { "id": 1, "name": "Product 1", "price": 100.00 }, { "id": 2, "name": "Product 2", "price": 150.00 } ]
-
POST
/product
- Creates a new product.
- Body:
{ "name": "Sample Product", "price": 100.00 }
- Example Response:
{ "id": 1, "name": "Sample Product", "price": 100.00 }
-
GET
/product/:productId
- Returns a specific product based on the ID.
- Example Response:
{ "id": 1, "name": "Sample Product", "price": 100.00 }
-
PUT
/product
- Updates an existing product.
- Body:
{ "id": 1, "name": "Updated Product", "price": 150.00 }
- Example Response:
{ "id": 1, "name": "Updated Product", "price": 150.00 }
-
DELETE
/product/:productId
- Removes a product based on the ID.
- Example Response:
{ "message": "Product successfully removed" }
- Golang: Main programming language.
- Gin: Lightweight and fast framework for API development.
- Docker: For container creation and management.
- PostgreSQL (or another relational database): Configured in the
db
module.