@mai0313/go_template 0.1.11

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 ADDED
@@ -0,0 +1,90 @@
1
+ <div align="center" markdown="1">
2
+
3
+ # Go Project Template
4
+
5
+ [![Go](https://img.shields.io/badge/Go-1.24+-00ADD8?logo=go&logoColor=white)](https://go.dev/dl/)
6
+ [![tests](https://github.com/Mai0313/go_template/actions/workflows/test.yml/badge.svg)](.github/workflows/test.yml)
7
+ [![code-quality](https://github.com/Mai0313/go_template/actions/workflows/code-quality-check.yml/badge.svg)](https://github.com/Mai0313/go_template/actions/workflows/code-quality-check.yml)
8
+ [![pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit)](https://github.com/pre-commit/pre-commit)
9
+ [![license](https://img.shields.io/badge/License-MIT-green.svg?labelColor=gray)](https://github.com/Mai0313/go_template/tree/master?tab=License-1-ov-file)
10
+ [![PRs](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](https://github.com/Mai0313/go_template/pulls)
11
+ [![contributors](https://img.shields.io/github/contributors/Mai0313/go_template.svg)](https://github.com/Mai0313/go_template/graphs/contributors)
12
+
13
+ </div>
14
+
15
+ 🚀 A production‑ready Golang project template to bootstrap new Go services and CLIs quickly. It ships with a pragmatic layout, Makefile, Docker builds, and a complete CI/CD suite.
16
+
17
+ Click [Use this template](../../generate) to start a new repository from this scaffold.
18
+
19
+ Other Languages: [English](README.md) | [繁體中文](README.zh-TW.md) | [简体中文](README.zh-CN.md)
20
+
21
+ ## ✨ Highlights
22
+
23
+ - Makefile tasks: build, test, cross‑compile, format, dead‑code scan
24
+ - Version embedding via `-ldflags` (version, build time, git commit)
25
+ - Example CLI under `cmd/go_template` with `--version`
26
+ - Unit tests with coverage artifact in CI
27
+ - Docker: multi‑stage image build with cache and minimal runtime
28
+ - GitHub Actions: test, lint (golangci‑lint), image build+push, release drafter, labels, secret/code scanning
29
+
30
+ ## 🚀 Quick Start
31
+
32
+ Prerequisites:
33
+
34
+ - Go 1.24+
35
+ - Docker (optional, for container builds)
36
+
37
+ Local setup:
38
+
39
+ ```bash
40
+ make build # build binaries into ./build/
41
+ make run # build and run the main command
42
+ make test # run unit tests with coverage
43
+ make fmt # format code (go fmt ./...)
44
+ make build-all # cross‑compile common OS/ARCH targets
45
+ ```
46
+
47
+ Run the example CLI:
48
+
49
+ ```bash
50
+ ./build/go_template --version
51
+ ```
52
+
53
+ Use as a template:
54
+
55
+ 1. Click Use this template to create your repository
56
+ 2. Replace module name in `go.mod` as needed
57
+ 3. Rename the command under `cmd/` if you want a different binary name
58
+
59
+ ## Project Structure
60
+
61
+ ```text
62
+ cmd/go_template/ # Main CLI entrypoint
63
+ core/version/ # Version utilities and tests
64
+ build/ # Build outputs (git‑ignored)
65
+ docker/Dockerfile # Multi‑stage image build
66
+ ```
67
+
68
+ ## Docker
69
+
70
+ ```bash
71
+ # Build & run image locally
72
+ docker build -t your/image:dev -f docker/Dockerfile .
73
+ docker run --rm -it your/image:dev
74
+ ```
75
+
76
+ ## CI/CD (GitHub Actions)
77
+
78
+ - tests: `.github/workflows/test.yml`
79
+ - quality: `.github/workflows/code-quality-check.yml`
80
+ - release package: `.github/workflows/build_release.yml`
81
+ - docker image: `.github/workflows/build_image.yml`
82
+ - release drafter: `.github/workflows/release_drafter.yml`
83
+ - labels & semantics: `.github/workflows/auto_labeler.yml`, `semantic-pull-request.yml`
84
+ - security: `.github/workflows/code_scan.yml` (gitleaks, trivy, codeql)
85
+
86
+ ## Contribution
87
+
88
+ - Run `make fmt && make test` before pushing
89
+ - Keep PRs focused and small; include tests
90
+ - Use Conventional Commit messages
@@ -0,0 +1,90 @@
1
+ <div align="center" markdown="1">
2
+
3
+ # Go 项目模板
4
+
5
+ [![Go](https://img.shields.io/badge/Go-1.24+-00ADD8?logo=go&logoColor=white)](https://go.dev/dl/)
6
+ [![tests](https://github.com/Mai0313/go_template/actions/workflows/test.yml/badge.svg)](.github/workflows/test.yml)
7
+ [![code-quality](https://github.com/Mai0313/go_template/actions/workflows/code-quality-check.yml/badge.svg)](https://github.com/Mai0313/go_template/actions/workflows/code-quality-check.yml)
8
+ [![pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit)](https://github.com/pre-commit/pre-commit)
9
+ [![license](https://img.shields.io/badge/License-MIT-green.svg?labelColor=gray)](https://github.com/Mai0313/go_template/tree/master?tab=License-1-ov-file)
10
+ [![PRs](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](https://github.com/Mai0313/go_template/pulls)
11
+ [![contributors](https://img.shields.io/github/contributors/Mai0313/go_template.svg)](https://github.com/Mai0313/go_template/graphs/contributors)
12
+
13
+ </div>
14
+
15
+ 🚀 面向 Golang 的生产级项目模板,帮助你快速创建新的 Go 服务或 CLI。内置合理的目录结构、Makefile、Docker 多阶段构建,以及完整的 CI/CD 工作流。
16
+
17
+ 点击 [使用此模板](../../generate) 开始。
18
+
19
+ 其他语言: [English](README.md) | [繁體中文](README.zh-TW.md) | [简体中文](README.zh-CN.md)
20
+
21
+ ## ✨ 特性
22
+
23
+ - Makefile 任务:build、test、交叉编译、fmt、dead‑code 扫描
24
+ - 版本信息嵌入:通过 `-ldflags` 注入 version、build time、git commit
25
+ - 示例 CLI:`cmd/go_template` 支持 `--version`
26
+ - 单元测试,CI 上传覆盖率 HTML 产物
27
+ - Docker:多阶段构建,最小化运行时镜像
28
+ - GitHub Actions:测试、静态检查(golangci‑lint)、镜像构建/推送、Release Drafter、标签、机密/代码扫描
29
+
30
+ ## 🚀 快速开始
31
+
32
+ 前置条件:
33
+
34
+ - Go 1.24+
35
+ - Docker(可选,用于容器构建)
36
+
37
+ 本地开发:
38
+
39
+ ```bash
40
+ make build # 编译到 ./build/
41
+ make run # 编译并运行主命令
42
+ make test # 运行单元测试并生成覆盖率
43
+ make fmt # go fmt ./...
44
+ make build-all # 交叉编译常见 OS/ARCH
45
+ ```
46
+
47
+ 运行示例 CLI:
48
+
49
+ ```bash
50
+ ./build/go_template --version
51
+ ```
52
+
53
+ 作为模板使用:
54
+
55
+ 1. 点击“使用此模板”创建你的仓库
56
+ 2. 按需修改 `go.mod` 的 module 名称
57
+ 3. 若需更换二进制名称,调整 `cmd/` 目录结构
58
+
59
+ ## 项目结构
60
+
61
+ ```text
62
+ cmd/go_template/ # 主 CLI 入口
63
+ core/version/ # 版本工具与测试
64
+ build/ # 编译输出(已被 .gitignore 忽略)
65
+ docker/Dockerfile # 多阶段镜像构建
66
+ ```
67
+
68
+ ## Docker
69
+
70
+ ```bash
71
+ # 本地构建与运行
72
+ docker build -t your/image:dev -f docker/Dockerfile .
73
+ docker run --rm -it your/image:dev
74
+ ```
75
+
76
+ ## CI/CD(GitHub Actions)
77
+
78
+ - 测试:`.github/workflows/test.yml`
79
+ - 质量:`.github/workflows/code-quality-check.yml`
80
+ - 发布打包:`.github/workflows/build_release.yml`
81
+ - Docker 镜像:`.github/workflows/build_image.yml`
82
+ - 发布草稿:`.github/workflows/release_drafter.yml`
83
+ - 标签与语义化:`.github/workflows/auto_labeler.yml`, `semantic-pull-request.yml`
84
+ - 安全:`.github/workflows/code_scan.yml`(gitleaks、trivy、codeql)
85
+
86
+ ## 贡献指南
87
+
88
+ - 提交前执行 `make fmt && make test`
89
+ - PR 聚焦单一变更并附带测试
90
+ - 使用 Conventional Commits 提交信息
@@ -0,0 +1,90 @@
1
+ <div align="center" markdown="1">
2
+
3
+ # Go 專案模板
4
+
5
+ [![Go](https://img.shields.io/badge/Go-1.24+-00ADD8?logo=go&logoColor=white)](https://go.dev/dl/)
6
+ [![tests](https://github.com/Mai0313/go_template/actions/workflows/test.yml/badge.svg)](.github/workflows/test.yml)
7
+ [![code-quality](https://github.com/Mai0313/go_template/actions/workflows/code-quality-check.yml/badge.svg)](https://github.com/Mai0313/go_template/actions/workflows/code-quality-check.yml)
8
+ [![pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit)](https://github.com/pre-commit/pre-commit)
9
+ [![license](https://img.shields.io/badge/License-MIT-green.svg?labelColor=gray)](https://github.com/Mai0313/go_template/tree/master?tab=License-1-ov-file)
10
+ [![PRs](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](https://github.com/Mai0313/go_template/pulls)
11
+ [![contributors](https://img.shields.io/github/contributors/Mai0313/go_template.svg)](https://github.com/Mai0313/go_template/graphs/contributors)
12
+
13
+ </div>
14
+
15
+ 🚀 幫助 Golang 開發者「快速建立新專案」的模板。提供務實的專案結構、Makefile、Docker 多階段建置,以及完整的 GitHub Actions 工作流程。
16
+
17
+ 點擊 [使用此模板](../../generate) 後即可開始。
18
+
19
+ 其他語言: [English](README.md) | [繁體中文](README.zh-TW.md) | [简体中文](README.zh-CN.md)
20
+
21
+ ## ✨ 重點特色
22
+
23
+ - Makefile 工作流:build、test、跨平台編譯、fmt、dead‑code 掃描
24
+ - 內建版本資訊:以 `-ldflags` 注入 version、build time、git commit
25
+ - 範例 CLI:`cmd/go_template`,支援 `--version`
26
+ - 單元測試與 CI 覆蓋率報告產物
27
+ - Docker:多階段建置,最小化執行環境
28
+ - GitHub Actions:測試、靜態檢查(golangci‑lint)、映像建置/推送、Release Drafter、標籤、自動秘密/程式碼掃描
29
+
30
+ ## 🚀 快速開始
31
+
32
+ 需求:
33
+
34
+ - Go 1.24+
35
+ - Docker(可選,用於容器化建置)
36
+
37
+ 本機開發:
38
+
39
+ ```bash
40
+ make build # 編譯到 ./build/
41
+ make run # 編譯並執行主程式
42
+ make test # 執行測試並輸出覆蓋率
43
+ make fmt # go fmt ./...
44
+ make build-all # 跨平台編譯常見 OS/ARCH
45
+ ```
46
+
47
+ 執行範例 CLI:
48
+
49
+ ```bash
50
+ ./build/go_template --version
51
+ ```
52
+
53
+ 作為模板使用:
54
+
55
+ 1. 點擊「使用此模板」建立你的倉庫
56
+ 2. 視需求修改 `go.mod` 的 module 名稱
57
+ 3. 若要更換二進位名稱,請調整 `cmd/` 目錄結構
58
+
59
+ ## 專案結構
60
+
61
+ ```text
62
+ cmd/go_template/ # 主 CLI 入口
63
+ core/version/ # 版本工具與測試
64
+ build/ # 編譯輸出(已加入 .gitignore)
65
+ docker/Dockerfile # 多階段映像建置
66
+ ```
67
+
68
+ ## Docker
69
+
70
+ ```bash
71
+ # 本地建置與執行
72
+ docker build -t your/image:dev -f docker/Dockerfile .
73
+ docker run --rm -it your/image:dev
74
+ ```
75
+
76
+ ## CI/CD(GitHub Actions)
77
+
78
+ - 測試:`.github/workflows/test.yml`
79
+ - 品質:`.github/workflows/code-quality-check.yml`
80
+ - 釋出打包:`.github/workflows/build_release.yml`
81
+ - Docker 映像:`.github/workflows/build_image.yml`
82
+ - 釋出草稿:`.github/workflows/release_drafter.yml`
83
+ - 標籤與語義化:`.github/workflows/auto_labeler.yml`, `semantic-pull-request.yml`
84
+ - 安全性:`.github/workflows/code_scan.yml`(gitleaks、trivy、codeql)
85
+
86
+ ## 貢獻指南
87
+
88
+ - 提交前請執行 `make fmt && make test`
89
+ - PR 請聚焦單一變更並附上測試
90
+ - 使用 Conventional Commits 作為提交訊息
package/bin/start.js ADDED
@@ -0,0 +1,90 @@
1
+ #!/usr/bin/env node
2
+
3
+ const { spawn } = require('child_process');
4
+ const path = require('path');
5
+ const fs = require('fs');
6
+
7
+ // Determine platform-specific directory and binary name
8
+ function getPlatformInfo() {
9
+ const platform = process.platform;
10
+ const arch = process.arch;
11
+
12
+ const platformMap = {
13
+ darwin: {
14
+ x64: { dir: 'macos-x64', binary: 'go_template' },
15
+ arm64: { dir: 'macos-arm64', binary: 'go_template' },
16
+ },
17
+ linux: {
18
+ x64: { dir: 'linux-x64-gnu', binary: 'go_template' },
19
+ arm64: { dir: 'linux-arm64-gnu', binary: 'go_template' },
20
+ },
21
+ win32: {
22
+ x64: { dir: 'windows-x64', binary: 'go_template.exe' },
23
+ arm64: { dir: 'windows-arm64', binary: 'go_template.exe' },
24
+ },
25
+ };
26
+
27
+ if (!platformMap[platform] || !platformMap[platform][arch]) {
28
+ console.error(`Unsupported platform: ${platform}-${arch}`);
29
+ process.exit(1);
30
+ }
31
+
32
+ return platformMap[platform][arch];
33
+ }
34
+
35
+ // Find the binary for current platform
36
+ function findBinary() {
37
+ const platformInfo = getPlatformInfo();
38
+ const packageRoot = path.join(__dirname, '..');
39
+ const binariesDir = path.join(packageRoot, 'binaries');
40
+
41
+ if (!fs.existsSync(binariesDir)) {
42
+ console.error('Error: Binaries directory not found.');
43
+ console.error('Please reinstall the package.');
44
+ process.exit(1);
45
+ }
46
+
47
+ // Look for the binary in platform-specific subdirectory
48
+ const platformDir = path.join(binariesDir, platformInfo.dir);
49
+ const binaryPath = path.join(platformDir, platformInfo.binary);
50
+
51
+ if (!fs.existsSync(binaryPath)) {
52
+ console.error(`Error: Binary not found for your platform: ${platformInfo.dir}/${platformInfo.binary}`);
53
+ console.error('Please reinstall the package.');
54
+ process.exit(1);
55
+ }
56
+
57
+ // Make binary executable on Unix-like systems
58
+ if (process.platform !== 'win32') {
59
+ try {
60
+ fs.chmodSync(binaryPath, 0o755);
61
+ } catch (err) {
62
+ // Ignore error if already executable
63
+ }
64
+ }
65
+
66
+ return binaryPath;
67
+ }
68
+
69
+ // Get binary path
70
+ const binaryPath = findBinary();
71
+
72
+ // Forward all arguments to the binary
73
+ const args = process.argv.slice(2);
74
+ const child = spawn(binaryPath, args, {
75
+ stdio: 'inherit',
76
+ windowsHide: true,
77
+ });
78
+
79
+ child.on('exit', (code, signal) => {
80
+ if (signal) {
81
+ process.kill(process.pid, signal);
82
+ } else {
83
+ process.exit(code);
84
+ }
85
+ });
86
+
87
+ child.on('error', (err) => {
88
+ console.error('Failed to start binary:', err);
89
+ process.exit(1);
90
+ });
package/package.json ADDED
@@ -0,0 +1,45 @@
1
+ {
2
+ "name": "@mai0313/go_template",
3
+ "version": "0.1.11",
4
+ "description": "A production-ready Go project template to bootstrap new projects fast. It includes a clean Go module layout, Docker, and a complete CI/CD suite.",
5
+ "author": "Wei Lee <mai@mai0313.com>",
6
+ "license": "MIT",
7
+ "homepage": "https://github.com/Mai0313/go_template",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/Mai0313/go_template.git"
11
+ },
12
+ "bugs": {
13
+ "url": "https://github.com/Mai0313/go_template/issues"
14
+ },
15
+ "keywords": [
16
+ "cli",
17
+ "go",
18
+ "golang",
19
+ "template",
20
+ "go-template",
21
+ "boilerplate",
22
+ "starter-kit"
23
+ ],
24
+ "bin": {
25
+ "go_template": "bin/start.js",
26
+ "gotemp": "bin/start.js"
27
+ },
28
+ "engines": {
29
+ "node": ">=18.0.0"
30
+ },
31
+ "os": [
32
+ "darwin",
33
+ "linux",
34
+ "win32"
35
+ ],
36
+ "cpu": [
37
+ "x64",
38
+ "arm64"
39
+ ],
40
+ "files": [
41
+ "bin/",
42
+ "binaries/",
43
+ "README.md"
44
+ ]
45
+ }