Skip to content

Commit 3cba80c

Browse files
authored
Merge pull request #6 from upsaurav12/new-template
New template
2 parents 1e6993a + c866014 commit 3cba80c

File tree

16 files changed

+139
-41
lines changed

16 files changed

+139
-41
lines changed

README.md

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,27 @@
1-
# Bootstrap CLI Tool
1+
# Go Bootstrapper 🐹⚡
22

3-
Bootstrap is a command-line tool designed to help developers quickly set up new projects using predefined templates. It supports various programming languages and frameworks, such as Go, Node.js, Python, and custom templates. This tool automates the process of creating new projects, initializing Git repositories, adding configuration files, and more.
3+
[![Go Version](https://img.shields.io/badge/Go-1.22-blue)](https://go.dev/)
4+
[![Build Status](https://github.com/upsaurav12/bootstrapper/actions/workflows/go.yml/badge.svg)](https://github.com/upsaurav12/bootstrapper/actions)
5+
[![License](https://img.shields.io/badge/license-MIT-green)](LICENSE)
6+
7+
A **CLI tool** to scaffold Go projects quickly — think of it like [Vite](https://vitejs.dev/), but for **Golang developers**.
8+
It saves you from boilerplate, folder structure confusion, and manual dependency setup.
49

510
---
611

7-
## Features
12+
## ✨ Features
13+
- 🚀 Create new Go projects in seconds
14+
- 📦 Preconfigured templates (REST API with Gin, Chi, etc.)
15+
- 🗂 Standardized folder structure (`cmd/`, `internal/`, `pkg/`)
16+
- 🔌 Incrementally add dependencies (DB, gRPC, logging, etc.)
17+
- 🧪 Built-in **Makefile** for build, test, and lint
18+
- ⚙️ GitHub Actions workflow for CI/CD
19+
- 🛠 Extensible via templates
20+
21+
---
822

9-
### 1. **Create a New Project**
23+
## 📂 Example Project Structure
1024

11-
With the `new` command, you can easily create a new project folder with a specified template. You can also specify a project name and additional flags for customizing the project setup.
25+
When you run `bootstrap new myapp --type=rest --router=gin --port=9000`,
26+
you’ll get something like this:
1227

13-
#### Example Command:
14-
```bash
15-
./bootstrap new my-go-project --template go

cmd/new.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,12 @@ func createNewProject(projectName string, projectRouter string, template string,
6262

6363
// Print the template that was passed
6464

65+
// Always add README + Makefile from common
66+
renderTemplateDir("templates/common", projectName, TemplateData{
67+
ModuleName: projectName,
68+
PortName: projectPort,
69+
})
70+
6571
renderTemplateDir("templates/"+template+"/"+projectRouter, projectName, TemplateData{
6672
ModuleName: projectName,
6773
PortName: projectPort,
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
run:
2+
timeout: 5m
3+
tests: true
4+
5+
linters:
6+
enable:
7+
- govet
8+
- errcheck
9+
- staticcheck
10+
- gofmt
11+
- ineffassign
12+
- unused

templates/common/Makefile.tmpl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
run:
2+
go run ./cmd/server/main.go
3+
4+
build:
5+
go build -o bin/server ./cmd/server/main.go
6+
7+
lint:
8+
golangci-lint run ./...
9+
10+
test:
11+
go test ./...

templates/common/README.md.tmpl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# {{ .ProjectName }}
2+
3+
Generated with go-scaffold (framework: {{ .Framework }}).
4+
5+
## 🚀 Run
6+
```bash
7+
make run
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package main
2+
3+
import (
4+
"log"
5+
"net/http"
6+
7+
"{{.ModuleName}}/internal/config"
8+
"{{.ModuleName}}/internal/router"
9+
10+
"github.com/go-chi/chi/v5"
11+
)
12+
13+
func main() {
14+
cfg := config.Load()
15+
16+
r := chi.NewRouter()
17+
router.RegisterRoutes(r)
18+
19+
port := cfg.Port
20+
if port == "" {
21+
port = "8080"
22+
}
23+
24+
log.Printf("Starting server on :%s", port)
25+
if err := http.ListenAndServe(":"+port, r); err != nil {
26+
log.Fatal(err)
27+
}
28+
}

templates/rest/chi/go.mod.tmpl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module {{.ModuleName}}
2+
3+
go 1.22
4+
5+
require github.com/go-chi/chi/v5 v5.0.11
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package config
2+
3+
import "os"
4+
5+
type Config struct {
6+
Port string
7+
}
8+
9+
func Load() Config {
10+
return Config{
11+
Port: getEnv("APP_PORT", "8080"),
12+
}
13+
}
14+
15+
func getEnv(key, fallback string) string {
16+
if value, ok := os.LookupEnv(key); ok {
17+
return value
18+
}
19+
return fallback
20+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package handler
2+
3+
import (
4+
"encoding/json"
5+
"net/http"
6+
7+
"github.com/go-chi/chi/v5"
8+
)
9+
10+
func GetUser(w http.ResponseWriter, r *http.Request) {
11+
id := chi.URLParam(r, "id")
12+
json.NewEncoder(w).Encode(map[string]string{
13+
"id": id,
14+
"name": "John Doe",
15+
})
16+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package router
2+
3+
import (
4+
handler "{{.ModuleName}}/internal/handler"
5+
6+
"github.com/go-chi/chi/v5"
7+
)
8+
9+
func RegisterRoutes(r *chi.Mux) {
10+
r.Get("/users/{id}", handler.GetUser)
11+
}

0 commit comments

Comments
 (0)