go-gin-cli 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +287 -0
- package/git-manager.sh +495 -0
- package/package.json +36 -0
- package/prompt.md +6 -0
- package/src/bin/index.js +410 -0
- package/src/lib/constants/index.js +24 -0
- package/src/lib/shares/createDir.js +22 -0
- package/src/lib/shares/createFile.js +23 -0
- package/src/lib/utils/add-auth-to-resource.js +225 -0
- package/src/lib/utils/create-auth.js +937 -0
- package/src/lib/utils/create-resource.js +1426 -0
- package/src/lib/utils/create-service.js +456 -0
- package/src/lib/utils/display.js +19 -0
- package/src/lib/utils/help.js +93 -0
- package/src/lib/utils/remove-module.js +146 -0
- package/src/lib/utils/setup.js +1626 -0
package/README.md
ADDED
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
# Go Clean Architecture CLI (gcg)
|
|
2
|
+
|
|
3
|
+
A CLI tool to generate Go/Gin clean architecture projects and modules. This tool helps you scaffold Go applications following clean architecture principles with Gin-Gonic framework.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- 🚀 **Project Scaffolding** - Generate a complete Go project with clean architecture structure
|
|
8
|
+
- 📦 **Resource Generator** - Create CRUD resources with entity, repository, usecase, and handler
|
|
9
|
+
- ⚡ **Service Generator** - Add custom services to existing resources
|
|
10
|
+
- 🗑️ **Module Removal** - Clean removal of resources
|
|
11
|
+
|
|
12
|
+
## Tech Stack
|
|
13
|
+
|
|
14
|
+
The generated projects use:
|
|
15
|
+
|
|
16
|
+
- **Framework**: [Gin-Gonic](https://github.com/gin-gonic/gin) - High-performance HTTP web framework
|
|
17
|
+
- **ORM**: [GORM](https://gorm.io/) - The fantastic ORM library for Go
|
|
18
|
+
- **Database**: PostgreSQL
|
|
19
|
+
- **Validation**: [go-playground/validator](https://github.com/go-playground/validator)
|
|
20
|
+
- **Configuration**: [Viper](https://github.com/spf13/viper) / godotenv
|
|
21
|
+
- **Logging**: [Zap](https://github.com/uber-go/zap) - Blazing fast structured logger
|
|
22
|
+
- **UUID**: [google/uuid](https://github.com/google/uuid)
|
|
23
|
+
|
|
24
|
+
## Installation
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
npm install -g go-clean-cli
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Or using npx:
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
npx go-clean-cli <command>
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Commands
|
|
37
|
+
|
|
38
|
+
### Create New Project
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
gcg new
|
|
42
|
+
# or
|
|
43
|
+
gcg n
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
This will:
|
|
47
|
+
1. Prompt for project name
|
|
48
|
+
2. Prompt for Go module name (e.g., `github.com/username/project`)
|
|
49
|
+
3. Generate complete project structure with clean architecture
|
|
50
|
+
|
|
51
|
+
### Generate Resource
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
gcg g res
|
|
55
|
+
# or
|
|
56
|
+
gcg g resource
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
This will:
|
|
60
|
+
1. Prompt for resource name (e.g., `user`, `product`, `order`)
|
|
61
|
+
2. Generate entity, repository, usecase, handler, and DTO files
|
|
62
|
+
3. Update router with CRUD endpoints
|
|
63
|
+
|
|
64
|
+
### Generate Service
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
gcg g s
|
|
68
|
+
# or
|
|
69
|
+
gcg g service
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
This will:
|
|
73
|
+
1. Select an existing module
|
|
74
|
+
2. Prompt for service name (e.g., `getByEmail`, `activate`)
|
|
75
|
+
3. Add service method to repository, usecase, and handler
|
|
76
|
+
|
|
77
|
+
### Remove Resource
|
|
78
|
+
|
|
79
|
+
```bash
|
|
80
|
+
gcg rm res
|
|
81
|
+
# or
|
|
82
|
+
gcg rm resource
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
This will:
|
|
86
|
+
1. List existing resources
|
|
87
|
+
2. Remove selected resource files and directories
|
|
88
|
+
3. Update router (manual cleanup may be needed)
|
|
89
|
+
|
|
90
|
+
### List Resources
|
|
91
|
+
|
|
92
|
+
```bash
|
|
93
|
+
gcg ls
|
|
94
|
+
# or
|
|
95
|
+
gcg list
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
### Help
|
|
99
|
+
|
|
100
|
+
```bash
|
|
101
|
+
gcg --help
|
|
102
|
+
# or
|
|
103
|
+
gcg -h
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
### Version
|
|
107
|
+
|
|
108
|
+
```bash
|
|
109
|
+
gcg --version
|
|
110
|
+
# or
|
|
111
|
+
gcg -v
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
## Project Structure
|
|
115
|
+
|
|
116
|
+
Generated projects follow the **NestJS Clean Architecture** pattern:
|
|
117
|
+
|
|
118
|
+
```
|
|
119
|
+
project-name/
|
|
120
|
+
├── src/
|
|
121
|
+
│ ├── domain/ # Domain layer (business logic)
|
|
122
|
+
│ │ ├── dtos/ # Data transfer objects
|
|
123
|
+
│ │ ├── logger/ # Logger interface
|
|
124
|
+
│ │ ├── models/ # Domain models
|
|
125
|
+
│ │ └── repositories/ # Repository interfaces
|
|
126
|
+
│ ├── infrastructure/ # Infrastructure layer
|
|
127
|
+
│ │ ├── common/
|
|
128
|
+
│ │ │ ├── filter/ # Exception filters
|
|
129
|
+
│ │ │ ├── interceptors/ # Request interceptors
|
|
130
|
+
│ │ │ └── middleware/ # HTTP middleware
|
|
131
|
+
│ │ ├── config/
|
|
132
|
+
│ │ │ ├── database/ # Database configuration
|
|
133
|
+
│ │ │ └── environment/ # Environment configuration
|
|
134
|
+
│ │ ├── controllers/ # HTTP controllers
|
|
135
|
+
│ │ ├── entities/ # Database entities (GORM)
|
|
136
|
+
│ │ ├── logger/ # Logger implementation
|
|
137
|
+
│ │ ├── repositories/ # Repository implementations
|
|
138
|
+
│ │ └── usecases-proxy/ # Usecases proxy (DI container)
|
|
139
|
+
│ ├── usecases/ # Application usecases
|
|
140
|
+
│ ├── shared/utils/ # Shared utilities
|
|
141
|
+
│ ├── main.go # Application entry point
|
|
142
|
+
│ └── app.go # Application module
|
|
143
|
+
├── .env # Environment variables
|
|
144
|
+
├── .env.example # Environment template
|
|
145
|
+
├── .gitignore
|
|
146
|
+
├── Dockerfile
|
|
147
|
+
├── docker-compose.yml
|
|
148
|
+
├── Makefile
|
|
149
|
+
└── go.mod
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
## Generated Resource Structure
|
|
153
|
+
|
|
154
|
+
When you generate a resource (e.g., `user`), the following files are created:
|
|
155
|
+
|
|
156
|
+
```
|
|
157
|
+
src/
|
|
158
|
+
├── domain/
|
|
159
|
+
│ ├── dtos/
|
|
160
|
+
│ │ └── user.go # User DTOs
|
|
161
|
+
│ ├── models/
|
|
162
|
+
│ │ └── user.go # User domain model
|
|
163
|
+
│ └── repositories/
|
|
164
|
+
│ └── user.go # User repository interface
|
|
165
|
+
├── infrastructure/
|
|
166
|
+
│ ├── controllers/user/
|
|
167
|
+
│ │ └── user.go # User HTTP controller
|
|
168
|
+
│ ├── entities/
|
|
169
|
+
│ │ └── user.go # User database entity
|
|
170
|
+
│ └── repositories/user/
|
|
171
|
+
│ └── user.go # User repository implementation
|
|
172
|
+
└── usecases/
|
|
173
|
+
└── user.go # User usecase implementation
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
## Quick Start
|
|
177
|
+
|
|
178
|
+
1. **Create a new project:**
|
|
179
|
+
```bash
|
|
180
|
+
gcg new
|
|
181
|
+
# Enter: my-api
|
|
182
|
+
# Enter: github.com/myuser/my-api
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
2. **Navigate to project:**
|
|
186
|
+
```bash
|
|
187
|
+
cd my-api
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
3. **Install dependencies:**
|
|
191
|
+
```bash
|
|
192
|
+
go mod tidy
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
4. **Set up database:**
|
|
196
|
+
```bash
|
|
197
|
+
# Create PostgreSQL database
|
|
198
|
+
createdb my_api
|
|
199
|
+
|
|
200
|
+
# Update .env with your database credentials
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
5. **Run the application:**
|
|
204
|
+
```bash
|
|
205
|
+
go run src/main.go
|
|
206
|
+
# or
|
|
207
|
+
make run
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
6. **Generate a resource:**
|
|
211
|
+
```bash
|
|
212
|
+
gcg g res
|
|
213
|
+
# Enter: user
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
7. **Add auto-migration in main.go:**
|
|
217
|
+
```go
|
|
218
|
+
import "github.com/myuser/my-api/domain/entity"
|
|
219
|
+
|
|
220
|
+
// After database connection
|
|
221
|
+
database.AutoMigrate(db, &entity.User{})
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
## API Endpoints
|
|
225
|
+
|
|
226
|
+
Generated resources include these endpoints:
|
|
227
|
+
|
|
228
|
+
| Method | Endpoint | Description |
|
|
229
|
+
|--------|----------|-------------|
|
|
230
|
+
| GET | `/api/v1/{resource}s` | Get all with pagination |
|
|
231
|
+
| GET | `/api/v1/{resource}s/:id` | Get by ID |
|
|
232
|
+
| POST | `/api/v1/{resource}s` | Create new |
|
|
233
|
+
| PUT | `/api/v1/{resource}s/:id` | Update existing |
|
|
234
|
+
| DELETE | `/api/v1/{resource}s/:id` | Delete (soft delete) |
|
|
235
|
+
|
|
236
|
+
### Query Parameters
|
|
237
|
+
|
|
238
|
+
- `page` - Page number (default: 1)
|
|
239
|
+
- `page_size` - Items per page (default: 10, max: 100)
|
|
240
|
+
- `search` - Search term
|
|
241
|
+
- `sort_by` - Sort field
|
|
242
|
+
- `sort_order` - Sort order (asc/desc)
|
|
243
|
+
|
|
244
|
+
## Makefile Commands
|
|
245
|
+
|
|
246
|
+
```bash
|
|
247
|
+
make build # Build the application
|
|
248
|
+
make run # Run the application
|
|
249
|
+
make test # Run tests
|
|
250
|
+
make test-coverage # Run tests with coverage
|
|
251
|
+
make clean # Clean build files
|
|
252
|
+
make fmt # Format code
|
|
253
|
+
make lint # Run linter
|
|
254
|
+
make tidy # Tidy dependencies
|
|
255
|
+
make docker-build # Build Docker image
|
|
256
|
+
make docker-run # Run with Docker Compose
|
|
257
|
+
make docker-stop # Stop Docker containers
|
|
258
|
+
make migrate-up # Run migrations
|
|
259
|
+
make migrate-down # Rollback migrations
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
## Environment Variables
|
|
263
|
+
|
|
264
|
+
| Variable | Description | Default |
|
|
265
|
+
|----------|-------------|---------|
|
|
266
|
+
| APP_NAME | Application name | project-name |
|
|
267
|
+
| APP_ENV | Environment (development/production) | development |
|
|
268
|
+
| APP_DEBUG | Debug mode | true |
|
|
269
|
+
| SERVER_HOST | Server host | 0.0.0.0 |
|
|
270
|
+
| SERVER_PORT | Server port | 8080 |
|
|
271
|
+
| SERVER_READ_TIMEOUT | Read timeout (seconds) | 10 |
|
|
272
|
+
| SERVER_WRITE_TIMEOUT | Write timeout (seconds) | 10 |
|
|
273
|
+
| DB_HOST | Database host | localhost |
|
|
274
|
+
| DB_PORT | Database port | 5432 |
|
|
275
|
+
| DB_USER | Database user | postgres |
|
|
276
|
+
| DB_PASSWORD | Database password | |
|
|
277
|
+
| DB_NAME | Database name | |
|
|
278
|
+
| DB_SSL_MODE | SSL mode | disable |
|
|
279
|
+
| DB_TIMEZONE | Timezone | UTC |
|
|
280
|
+
|
|
281
|
+
## License
|
|
282
|
+
|
|
283
|
+
MIT
|
|
284
|
+
|
|
285
|
+
## Contributing
|
|
286
|
+
|
|
287
|
+
Contributions are welcome! Please feel free to submit a Pull Request.
|