返回 Skill 列表
extension
分类: 开发与工程无需 API Key

go-service-scaffolder

使用OpenTelemetry可观测性、TLS、生命周期管理、Dockerfile、GitHub Actions CI/CD和golangci-lint搭建一个生产就绪的Go HTTP服务。在创建或重新生成完整的Go服务框架(项目布局、配置包、服务器包、CI工作流和容器构建文件)时使用。

person作者: jakexiaohubgithub

Go Service Scaffolder

Create a production-ready Go HTTP service skeleton and keep outputs consistent.

Workflow

  1. Ask for required inputs:
  • App name (kebab-case)
  • Go module path
  • GitHub owner/org
  • If the user asks for database support, ask which database to scaffold: Postgres, SQLite, or both.
  1. Derive:
  • CONFIG_ENV_VAR: uppercase app name without hyphens + _CONFIG
  • METRICS_PREFIX: lowercase app name without hyphens
  1. Generate the full project file tree and file contents using the canonical spec in references/go-service-scaffold-spec.md.

  2. Replace placeholders everywhere:

  • {{APP_NAME}}
  • {{MODULE_PATH}}
  • {{GITHUB_OWNER}}
  • {{CONFIG_ENV_VAR}}
  • {{METRICS_PREFIX}}

Database constraints when database support is requested:

  • Never use an ORM.
  • For Postgres, use PGX: github.com/jackc/pgx/v5.
  • For SQLite, use modernc.org/sqlite.
  1. Run:
  • go mod init <module-path> (only if go.mod does not already exist)
  • go mod tidy
  • go get -tool github.com/italypaleale/go-kit/tools/gen-config (adds the tool directive used by make gen-config)
  • make gen-config to produce config.md and config.sample.yaml from the Config struct
  • go test ./...
  1. Initialize git only when needed:
  • Run git init only if the target directory is not already a git repository.

Whenever pkg/config.Config (or any struct reachable from it) is regenerated or edited later, re-run make gen-config so config.md and config.sample.yaml stay in sync. CI enforces this with make check-config-diff.

Reference

Use references/go-service-scaffold-spec.md as the single source of truth for:

  • Required directory structure
  • Exact file templates
  • Post-scaffold steps and architecture notes

Load only the sections needed for the current task instead of reading the entire reference at once.