Skip to content

Commit 3c7c376

Browse files
committed
feat: create documentation, and fixed main.go
1 parent 6981e94 commit 3c7c376

File tree

5 files changed

+177
-154
lines changed

5 files changed

+177
-154
lines changed

README.md

Lines changed: 19 additions & 153 deletions
Original file line numberDiff line numberDiff line change
@@ -1,171 +1,37 @@
1-
# API-GO: Product Management with JWT Verification
1+
# 🚀 API-GO: Product Management with JWT Verification
22

3-
This project is an API for product management developed in **Go** using the **Gin** framework. The architecture is modular, ensuring better organization and maintainability.
3+
[![Go](https://img.shields.io/badge/Go-1.21-blue?logo=go)](https://golang.org/)
4+
[![Gin](https://img.shields.io/badge/Gin-Framework-brightgreen?logo=gin)](https://gin-gonic.com/)
5+
[![Docker](https://img.shields.io/badge/Docker-Container-blue?logo=docker)](https://www.docker.com/)
6+
[![PostgreSQL](https://img.shields.io/badge/PostgreSQL-Database-blue?logo=postgresql)](https://www.postgresql.org/)
47

5-
<br>
8+
API for product management, developed in **Go** with the **Gin** framework. Modular architecture ensures clean organization and maintainability.
69

710
---
811

9-
## 🚀 Project Initialization
12+
## 📥 Installation & Setup
1013

11-
12-
### Pre-requisites
13-
14-
Make sure you have installed:
15-
- **Golang**: [Install Golang](https://go.dev/doc/install)
16-
- **Docker**: [Install Docker](https://www.docker.com/products/docker-desktop)
17-
18-
---
19-
20-
### How to Run
21-
22-
1. Clone the project and navigate to the folder:
23-
```bash
24-
git clone https://github.com/usuario/api-go.git
25-
cd api-go
26-
```
27-
28-
2. Configure the database connection:
29-
Edit the settings in the `db/conn.go` file to reflect your credentials.
30-
31-
3. Start the services with Docker:
32-
```bash
33-
docker-compose up
34-
```
35-
36-
4. Access the API at the address:
37-
- `http://localhost:8000`
38-
39-
---
40-
41-
## 📚 Project Structure
42-
43-
The structure is organized as follows:
44-
45-
```plaintext
46-
API-GO/
47-
├── cmd/
48-
│ └── main.go # Main file to start the application
49-
├── controller/
50-
│ └── product_controller.go # Controllers responsible for the routes
51-
├── db/
52-
│ └── conn.go # Database configuration and connection
53-
├── model/
54-
│ ├── product.go # Product model
55-
│ └── response.go # Response structures for the API
56-
├── repository/
57-
│ └── product_repository.go # Layer for interacting with the database
58-
├── usecase/
59-
│ └── product_usecase.go # Business logic and application logic
60-
├── .gitignore # Files ignored in version control
61-
├── docker-compose.yml # Docker Compose configuration
62-
├── Dockerfile # Docker container configuration
63-
├── go.mod # Project dependencies
64-
├── go.sum # Dependency hashes
65-
└── README.md # Project documentation
66-
```
14+
Follow instructions in [INSTALLATION.md](INSTALLATION.md)
6715

6816
---
6917

70-
## 📖 Endpoints
18+
## 📂 Project Structure
7119

72-
### **Ping**
73-
- **GET `/ping`**
74-
- Returns a test message.
75-
- **Response**:
76-
```json
77-
{
78-
"message": "initial tests"
79-
}
80-
```
20+
View full structure in [STRUCTURE.md](STRUCTURE.md)
8121

8222
---
8323

84-
### **Products**
85-
- **GET `/products`**
86-
- Lists all registered products.
87-
- **Example Response**:
88-
```json
89-
[
90-
{
91-
"id": 1,
92-
"name": "Product 1",
93-
"price": 100.00
94-
},
95-
{
96-
"id": 2,
97-
"name": "Product 2",
98-
"price": 150.00
99-
}
100-
]
101-
```
102-
103-
- **POST `/product`**
104-
- Creates a new product.
105-
- **Body**:
106-
```json
107-
{
108-
"name": "Sample Product",
109-
"price": 100.00
110-
}
111-
```
112-
- **Example Response**:
113-
```json
114-
{
115-
"id": 1,
116-
"name": "Sample Product",
117-
"price": 100.00
118-
}
119-
```
24+
## 📖 API Endpoints
12025

121-
- **GET `/product/:productId`**
122-
- Returns a specific product based on the ID.
123-
- **Example Response**:
124-
```json
125-
{
126-
"id": 1,
127-
"name": "Sample Product",
128-
"price": 100.00
129-
}
130-
```
131-
132-
- **PUT `/product`**
133-
- Updates an existing product.
134-
- **Body**:
135-
```json
136-
{
137-
"id": 1,
138-
"name": "Updated Product",
139-
"price": 150.00
140-
}
141-
```
142-
- **Example Response**:
143-
``` json
144-
{
145-
"id": 1,
146-
"name": "Updated Product",
147-
"price": 150.00
148-
}
149-
```
150-
151-
- **DELETE `/product/:productId`**
152-
- Removes a product based on the ID.
153-
- **Example Response**:
154-
``` json
155-
{
156-
"message": "Product successfully removed"
157-
}
158-
```
26+
Full route documentation in [ENDPOINTS.md](ENDPOINTS.md)
15927

16028
---
16129

162-
## 🛠️ Technologies Used
163-
164-
- **Golang**: Main programming language.
165-
- **Gin**: Lightweight and fast framework for API development.
166-
- **Docker**: For container creation and management.
167-
- **PostgreSQL** (or another relational database): Configured in the `db` module.
30+
## 🛠️ Technologies
16831

169-
<br>
170-
171-
---
32+
| Technology | Description |
33+
|------------|-------------|
34+
| 🟦 Golang | Main programming language |
35+
| 🟩 Gin | Fast and lightweight API framework |
36+
| 🐳 Docker | Containerization and orchestration |
37+
| 🐘 PostgreSQL | Relational database system |

cmd/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"api-go/middleware"
77
"api-go/repository"
88
"api-go/usecase"
9+
910
"github.com/gin-gonic/gin"
1011
)
1112

@@ -16,7 +17,6 @@ func main() {
1617

1718
if err != nil {
1819
panic(err)
19-
return err
2020
}
2121

2222
ProductRepository := repository.NewProductRepository(dbConnection)

docs/ENDPOINTS.md

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
# 📖 API Endpoints
2+
3+
---
4+
5+
## 🟢 Ping
6+
**GET `/ping`**
7+
Returns a test message.
8+
9+
-------------------------
10+
{
11+
"message": "initial tests"
12+
}
13+
-------------------------
14+
15+
---
16+
17+
## 📦 Products
18+
19+
### 🔹 List All Products
20+
**GET `/products`**
21+
Returns all registered products.
22+
23+
-------------------------
24+
[
25+
{
26+
"id": 1,
27+
"name": "Product 1",
28+
"price": 100.00
29+
},
30+
{
31+
"id": 2,
32+
"name": "Product 2",
33+
"price": 150.00
34+
}
35+
]
36+
-------------------------
37+
38+
---
39+
40+
### 🔹 Create a Product
41+
**POST `/product`**
42+
43+
**Body**
44+
-------------------------
45+
{
46+
"name": "Sample Product",
47+
"price": 100.00
48+
}
49+
-------------------------
50+
51+
**Response**
52+
-------------------------
53+
{
54+
"id": 1,
55+
"name": "Sample Product",
56+
"price": 100.00
57+
}
58+
-------------------------
59+
60+
---
61+
62+
### 🔹 Get Product by ID
63+
**GET `/product/:productId`**
64+
Returns a specific product by its ID.
65+
66+
-------------------------
67+
{
68+
"id": 1,
69+
"name": "Sample Product",
70+
"price": 100.00
71+
}
72+
-------------------------
73+
74+
---
75+
76+
### 🔹 Update Product
77+
**PUT `/product`**
78+
79+
**Body**
80+
-------------------------
81+
{
82+
"id": 1,
83+
"name": "Updated Product",
84+
"price": 150.00
85+
}
86+
-------------------------
87+
88+
**Response**
89+
-------------------------
90+
{
91+
"id": 1,
92+
"name": "Updated Product",
93+
"price": 150.00
94+
}
95+
-------------------------
96+
97+
---
98+
99+
### 🔹 Delete Product
100+
**DELETE `/product/:productId`**
101+
Removes a product by its ID.
102+
103+
-------------------------
104+
{
105+
"message": "Product successfully removed"
106+
}
107+
-------------------------

docs/INSTALLATION.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# 🚀 Project Initialization
2+
3+
## ⚙️ Prerequisites
4+
- **Golang**: [Install Golang](https://go.dev/doc/install)
5+
- **Docker**: [Install Docker](https://www.docker.com/products/docker-desktop)
6+
7+
---
8+
9+
## 🏃 How to Run
10+
11+
1. **Clone the repository**
12+
-------------------------
13+
git clone https://github.com/usuario/api-go.git
14+
cd api-go
15+
-------------------------
16+
17+
2. **Configure the database**
18+
Edit `db/conn.go` with your credentials.
19+
20+
3. **Start services with Docker**
21+
-------------------------
22+
docker-compose up
23+
-------------------------
24+
25+
4. **Access the API**
26+
- URL: `http://localhost:8000`

docs/STRUCTURE.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# 📚 Project Structure
2+
3+
-------------------------
4+
API-GO/
5+
├── cmd/
6+
│ └── main.go # Entry point of the application
7+
├── controller/
8+
│ └── product_controller.go # Routes and controllers
9+
├── db/
10+
│ └── conn.go # Database configuration
11+
├── model/
12+
│ ├── product.go # Product model
13+
│ └── response.go # API response structures
14+
├── repository/
15+
│ └── product_repository.go # Database interaction layer
16+
├── usecase/
17+
│ └── product_usecase.go # Business logic
18+
├── .gitignore # Files ignored by git
19+
├── docker-compose.yml # Docker Compose configuration
20+
├── Dockerfile # Docker container configuration
21+
├── go.mod # Go modules dependencies
22+
├── go.sum # Dependency hashes
23+
└── README.md # Project documentation
24+
-------------------------

0 commit comments

Comments
 (0)