Skip to content

Commit 358c877

Browse files
committed
Added the module feature
Signed-off-by: vviveksharma <visharma@progress.com>
1 parent 0a1d065 commit 358c877

13 files changed

Lines changed: 162 additions & 75 deletions

File tree

.github/dependabot.yml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@ updates:
88
interval: "weekly"
99
day: "monday"
1010
open-pull-requests-limit: 5
11-
labels:
12-
- "dependencies"
13-
- "github-actions"
1411

1512
# Go modules
1613
- package-ecosystem: "gomod"
@@ -19,9 +16,6 @@ updates:
1916
interval: "weekly"
2017
day: "monday"
2118
open-pull-requests-limit: 5
22-
labels:
23-
- "dependencies"
24-
- "go"
2519
groups:
2620
# Group all patch and minor updates together
2721
minor-patch:

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ jobs:
3535
run: go test -v -race -coverprofile=coverage.out -covermode=atomic ./...
3636

3737
- name: Upload coverage to Codecov
38-
uses: codecov/codecov-action@v4
38+
uses: codecov/codecov-action@v6
3939
if: matrix.os == 'ubuntu-latest'
4040
with:
4141
files: ./coverage.out

README.md

Lines changed: 129 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -23,30 +23,47 @@ go build -o goforge ./cmd/goforge
2323
sudo mv goforge /usr/local/bin/
2424
```
2525

26-
## 📖 Usage
26+
## 📖 Quick Start
2727

28-
Create a new project with your choice of web framework:
28+
### Basic Usage
29+
30+
Create a new project in seconds:
2931

3032
```bash
31-
# Using Fiber (high performance)
32-
goforge create my-awesome-api --server fiber
33-
# or shorthand
34-
goforge create my-awesome-api -s fiber
35-
36-
# Using Gin (popular, feature-rich)
37-
goforge create my-awesome-api --server gin
38-
# or shorthand
39-
goforge create my-awesome-api -s gin
33+
# Create with Fiber (high performance)
34+
goforge create my-api -s fiber
35+
36+
# Create with Gin (feature-rich)
37+
goforge create my-api -s gin
4038
```
4139

42-
Then start developing:
40+
### Custom Module Path (Optional)
41+
42+
By default, your Go module will be named after your project (e.g., `module my-api`).
43+
44+
If you want a custom module path for GitHub/GitLab or organization projects:
4345

4446
```bash
45-
cd my-awesome-api
47+
# With custom module path
48+
goforge create my-api -s fiber --module github.com/yourusername/my-api
49+
50+
# Short form
51+
goforge create my-api -s fiber -m github.com/viveksharma/my-api
52+
```
53+
54+
### Start Developing
55+
56+
```bash
57+
cd my-api
4658
make up
4759
```
4860

49-
Visit `http://localhost:8080/health/ready` to verify the API is running.
61+
Your API is now running at `http://localhost:8080` 🚀
62+
63+
**Quick health check:**
64+
```bash
65+
curl http://localhost:8080/health/ready
66+
```
5067

5168
## ✨ What You Get
5269

@@ -214,57 +231,127 @@ Add your tests in:
214231

215232
## 📖 Examples
216233

217-
### Create a Fiber-based API (default)
234+
### Simple Project (Local Development)
235+
236+
For quick prototyping or local projects, use the simple syntax:
218237

219238
```bash
220-
goforge create my-fiber-api
221-
# or explicitly: goforge create my-fiber-api --server fiber
239+
goforge create my-api -s fiber
240+
# Result: go.mod → module my-api
222241
```
223242

224-
### Create a Gin-based API
243+
### GitHub/GitLab Project
244+
245+
For projects you'll push to GitHub or GitLab, specify the full module path:
225246

226247
```bash
227-
goforge create my-gin-api --server gin
248+
goforge create my-api -s fiber -m github.com/yourusername/my-api
249+
# Result: go.mod → module github.com/yourusername/my-api
228250
```
229251

230-
### What happens:
252+
### Organization/Company Project
253+
254+
For company or organization projects:
255+
256+
```bash
257+
goforge create payment-service -s gin -m gitlab.company.com/backend/payment-service
258+
# Result: go.mod → module gitlab.company.com/backend/payment-service
259+
```
260+
261+
### What Happens When You Create a Project
231262

232263
1. ✅ Creates project directory
233-
2. ✅ Generates all project files
234-
3. ✅ Sets up your chosen web framework (Fiber or Gin)
235-
4. ✅ Configures PostgreSQL and Redis
236-
5. ✅ Adds health check endpoints
237-
6. ✅ Sets up database migrations
238-
7. ✅ Generates Swagger/OpenAPI docs
239-
8. ✅ Adds Prometheus metrics endpoint
240-
9. ✅ Includes Docker Compose
241-
10. ✅ Creates comprehensive README
242-
11.Runs `go mod tidy` automatically
243-
244-
### Start developing immediately
264+
2. ✅ Generates all project files with your chosen framework
265+
3. ✅ Sets up PostgreSQL database with connection pooling
266+
4. ✅ Configures Redis for caching
267+
5. ✅ Adds health check endpoints (`/health/live`, `/health/ready`)
268+
6. ✅ Sets up database migrations system
269+
7. ✅ Generates Swagger/OpenAPI docs at `/swagger/index.html`
270+
8. ✅ Adds Prometheus metrics at `/metrics`
271+
9. ✅ Includes Docker Compose for one-command startup
272+
10. ✅ Creates comprehensive README with all commands
273+
11.Downloads dependencies automatically
274+
275+
### Start Coding Immediately
245276

246277
```bash
247-
cd my-fiber-api # or my-gin-api
248-
make up
278+
cd my-api
279+
make up # Starts PostgreSQL, Redis, and your API
280+
make logs # Watch the logs
281+
282+
# Test your API
249283
curl http://localhost:8080/health/ready
284+
curl http://localhost:8080/metrics
285+
286+
# View API docs
287+
open http://localhost:8080/swagger/index.html
250288
```
251289

252290
## 🔀 Choosing a Framework
253291

254292
### Use Fiber when:
255-
- You need maximum performance and minimal memory footprint
256-
- You prefer Express.js-like syntax and patterns
257-
- Your application handles high concurrent loads
258-
- You want the fastest request/response times
293+
- 🚀 You need **maximum performance** and minimal memory footprint
294+
- 💚 You prefer **Express.js-like** syntax and patterns
295+
- Your application handles **high concurrent loads**
296+
- 🏎️ You want the **fastest** request/response times
259297

260298
### Use Gin when:
261-
- You prefer a mature, battle-tested framework
262-
- You need extensive middleware ecosystem
263-
- You want built-in validation and binding
264-
- Your team is already familiar with Gin
299+
- 🛡️ You prefer a **mature, battle-tested** framework
300+
- 🔧 You need **extensive middleware** ecosystem
301+
- You want **built-in validation** and binding
302+
- 👥 Your team is **already familiar** with Gin
265303

266304
**Both frameworks generate identical project structure and features** - the only difference is the web framework implementation.
267305

306+
## 🎯 Module Path Guide
307+
308+
### When to Use Default (No `--module` flag)
309+
310+
```bash
311+
goforge create my-project -s fiber
312+
```
313+
314+
**Perfect for:**
315+
- Quick prototypes and experiments
316+
- Learning projects
317+
- Local-only development
318+
- Tools and scripts that won't be shared
319+
320+
**Result:** `module my-project` (simple and clean)
321+
322+
### When to Use Custom Module Path
323+
324+
```bash
325+
goforge create my-project -s fiber -m github.com/username/my-project
326+
```
327+
328+
**Perfect for:**
329+
- Projects you'll push to GitHub/GitLab
330+
- Open source projects
331+
- Company/organization codebases
332+
- Projects with internal imports
333+
334+
**Result:** `module github.com/username/my-project`
335+
336+
### Module Path Examples
337+
338+
```bash
339+
# GitHub
340+
goforge create api -s fiber -m github.com/viveksharma/api
341+
342+
# GitLab
343+
goforge create service -s gin -m gitlab.com/myorg/service
344+
345+
# Self-hosted GitLab
346+
goforge create payment -s fiber -m git.company.com/backend/payment
347+
348+
# Bitbucket
349+
goforge create auth -s gin -m bitbucket.org/team/auth
350+
351+
# Company domain
352+
goforge create users -s fiber -m go.company.com/services/users
353+
```
354+
268355
## 🤝 Contributing
269356

270357
Contributions welcome! Please see [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines.

go.mod

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ module github.com/viveksharma/goforge
33
go 1.26.2
44

55
require (
6-
github.com/spf13/cobra v1.8.0
7-
github.com/stretchr/testify v1.9.0
6+
github.com/spf13/cobra v1.10.2
7+
github.com/stretchr/testify v1.11.1
88
)
99

1010
require (
1111
github.com/davecgh/go-spew v1.1.1 // indirect
1212
github.com/inconshreveable/mousetrap v1.1.0 // indirect
1313
github.com/pmezard/go-difflib v1.0.0 // indirect
14-
github.com/spf13/pflag v1.0.5 // indirect
14+
github.com/spf13/pflag v1.0.10 // indirect
1515
gopkg.in/yaml.v3 v3.0.1 // indirect
1616
)

go.sum

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
1-
github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
1+
github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g=
22
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
33
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
44
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
55
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
66
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
77
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
88
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
9-
github.com/spf13/cobra v1.8.0 h1:7aJaZx1B85qltLMc546zn58BxxfZdR/W22ej9CFoEf0=
10-
github.com/spf13/cobra v1.8.0/go.mod h1:WXLWApfZ71AjXPya3WOlMsY9yMs7YeiHhFVlvLyhcho=
11-
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
12-
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
13-
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
14-
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
9+
github.com/spf13/cobra v1.10.2 h1:DMTTonx5m65Ic0GOoRY2c16WCbHxOOw6xxezuLaBpcU=
10+
github.com/spf13/cobra v1.10.2/go.mod h1:7C1pvHqHw5A4vrJfjNwvOdzYu0Gml16OCs2GRiTUUS4=
11+
github.com/spf13/pflag v1.0.9/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
12+
github.com/spf13/pflag v1.0.10 h1:4EBh2KAYBwaONj6b2Ye1GiHfwjqyROoF4RwYO+vPwFk=
13+
github.com/spf13/pflag v1.0.10/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
14+
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
15+
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
16+
go.yaml.in/yaml/v3 v3.0.4/go.mod h1:DhzuOOF2ATzADvBadXxruRBLzYTpT36CKvDb3+aBEFg=
1517
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
1618
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
1719
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=

internal/cmd/create.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515

1616
var (
1717
serverType string
18+
modulePath string
1819
)
1920

2021
// CreateOptions contains dependencies for the create command.
@@ -35,6 +36,7 @@ var createCmd = &cobra.Command{
3536

3637
func init() {
3738
createCmd.Flags().StringVarP(&serverType, "server", "s", "", "Web framework to use (fiber or gin) [REQUIRED]")
39+
createCmd.Flags().StringVarP(&modulePath, "module", "m", "", "Go module path (e.g., github.com/user/project). Defaults to project name")
3840
if err := createCmd.MarkFlagRequired("server"); err != nil {
3941
panic(fmt.Sprintf("failed to mark server flag as required: %v", err))
4042
}
@@ -89,10 +91,16 @@ func runCreateWithDeps(opts CreateOptions, cmd *cobra.Command, args []string) er
8991
opts.Writer.Printf("📦 Server framework: %s\n", serverType)
9092

9193
// Generate project
94+
// Use custom module path if provided, otherwise default to project name
95+
modPath := modulePath
96+
if modPath == "" {
97+
modPath = projectName
98+
}
99+
92100
config := generator.ProjectConfig{
93101
ProjectName: projectName,
94102
ProjectPath: projectPath,
95-
ModulePath: fmt.Sprintf("github.com/yourusername/%s", projectName),
103+
ModulePath: modPath,
96104
ServerType: serverType,
97105
}
98106

internal/generator/templates/Makefile.tmpl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ help: ## Show this help message
77
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf " %-15s %s\n", $$1, $$2}' $(MAKEFILE_LIST)
88

99
up: ## Start all services (API, PostgreSQL, Redis)
10-
docker-compose up -d
10+
docker compose up -d
1111
@echo "✅ Services started. API: http://localhost:8080"
1212

1313
down: ## Stop all services
14-
docker-compose down
14+
docker compose down
1515

1616
logs: ## View logs from all services
17-
docker-compose logs -f
17+
docker compose logs -f
1818

1919
build: ## Build the Go binary
2020
go build -o bin/{{.ProjectName}} cmd/api/main.go
@@ -38,10 +38,10 @@ clean: ## Clean up build artifacts and stop services
3838
rm -f coverage.out
3939

4040
db-connect: ## Connect to PostgreSQL database
41-
docker-compose exec postgres psql -U {{.ProjectName}}_user -d {{.ProjectName}}_db
41+
docker compose exec postgres psql -U {{.ProjectName}}_user -d {{.ProjectName}}_db
4242

4343
redis-cli: ## Connect to Redis CLI
44-
docker-compose exec redis redis-cli
44+
docker compose exec redis redis-cli
4545

4646
migrate-up: ## Run all pending migrations
4747
@echo "Running migrations..."

internal/generator/templates/README.md.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ make up
263263
**Redis connection failed:**
264264
```bash
265265
# Check Redis logs
266-
docker-compose logs redis
266+
docker compose logs redis
267267
```
268268

269269
## 📄 License

internal/generator/templates/cmd/api/main.go.tmpl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import (
1212

1313
"{{.ModulePath}}/internal/config"
1414
"{{.ModulePath}}/internal/server"
15-
"{{.ModulePath}}/pkg/database"
1615
"{{.ModulePath}}/pkg/logger"
1716
"{{.ModulePath}}/pkg/migration"
1817
)

internal/generator/templates/deployments/Dockerfile.tmpl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@ COPY . .
1919
# Build binary with security flags
2020
# -trimpath: removes file system paths from the binary
2121
# -ldflags "-s -w": strip debug information (smaller binary)
22-
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build \
22+
RUN VERSION=$(git describe --tags --always --dirty 2>/dev/null || echo "dev") && \
23+
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build \
2324
-trimpath \
24-
-ldflags="-s -w -X main.version=$(git describe --tags --always --dirty)" \
25+
-ldflags="-s -w -X main.version=${VERSION}" \
2526
-o api \
2627
cmd/api/main.go
2728

0 commit comments

Comments
 (0)