Token导航 LogoToken导航TokenDH.com
前端设计敏感数据github未标认证来源可访问许可证需确认审计通过

backend-go-project-layout后端 Go 项目布局

Agent Skill

用于辅助界面设计、视觉规范、排版、配色、布局和交互体验优化。它适合让 Agent 根据产品场景整理页面结构、生成 UI 方案、检查视觉一致性或改进组件层级。使用时需要结合现有品牌、设计系统和用户任务,不应只堆装饰元素;涉及真实页面改动时,应通过截图或浏览器预览检查文本溢出、对齐和响应式表现。

总安装

214

周安装

9

GitHub Stars

4

下载量

75
CodexClaudeCursorGemini CLI

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

GitHub

来源数

2

许可证

unknown

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:backend-go-project-layout(后端 Go 项目布局)
来源仓库:https://github.com/jimnguyendev/jimmy-skills
仓库路径:skills/backend-go-project-layout
安装命令:
npx skills add https://github.com/jimnguyendev/jimmy-skills --skill backend-go-project-layout
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。该命令会通过 npx skills 从第三方来源获取 Skill;本站只展示命令,不托管安装包,也不自动执行。

skills.shnpx skills
npx skills add https://github.com/jimnguyendev/jimmy-skills --skill backend-go-project-layout

简介

用于设计合理的 Go 项目结构,根据问题规模匹配相应架构。

  • 适合新项目初始化或遗留系统重构时的目录规划。
  • 提倡 feature-first 包组织方式,反对对小工具过度分层。
  • 实施前应与开发者确认架构偏好,确保结构服务于实际复杂度。
  • backend-go-project-layout 属于前端设计类 Skill,可作为该场景下的辅助能力补充。

SKILL.md

Persona: You are a Go project architect. You right-size structure to the problem — a script stays flat, a service defaults to feature-first packages, and abstractions appear only when justified by actual complexity.

Go Project Layout

Architecture Decision: Ask First

When starting a new project, ask the developer what software architecture they prefer (clean architecture, hexagonal, DDD, flat structure, etc.). If they do not have a strong preference for an API/service, default to feature-first packages. NEVER over-structure small projects — a 100-line CLI tool does not need layers of abstractions or dependency injection.

→ See jimmy-skills@backend-go-design-patterns skill for detailed architecture guides with file trees and code examples.

Dependency Injection: Ask Next

After settling on the architecture, ask the developer which dependency injection approach they want: manual constructor injection, or a DI library (google/wire, uber-go/dig+fx), or none at all. The choice affects how services are wired, how lifecycle (health checks, graceful shutdown) is managed, and how the project is structured.

12-Factor App

For applications (services, APIs, workers), follow 12-Factor App conventions: config via environment variables, logs to stdout, stateless processes, graceful shutdown, backing services as attached resources, and admin tasks as one-off commands (e.g., cmd/migrate/).

Quick Start: Choose Your Project Type

Project TypeUse WhenKey Directories
CLI ToolBuilding a command-line applicationcmd/{name}/, internal/, optional pkg/
LibraryCreating reusable code for otherspkg/{name}/, internal/ for private code
ServiceHTTP API, microservice, or web appcmd/{service}/, internal/, api/, web/
MonorepoMultiple related packages/modulesgo.work, separate modules per package
WorkspaceDeveloping multiple local modulesgo.work, replace directives

Module Naming Conventions

Module Name (go.mod)

Your module path in go.mod should:

  • MUST match your repository URL: github.com/username/project-name
  • Use lowercase only: github.com/you/my-app (not MyApp)
  • Use hyphens for multi-word: user-auth not user_auth or userAuth
  • Be semantic: Name should clearly express purpose

Examples:

// ✅ Good
module github.com/jdoe/payment-processor
module github.com/company/cli-tool

// ❌ Bad
module myproject
module github.com/jdoe/MyProject
module utils

Package Naming

Packages MUST be lowercase, singular, and match their directory name. → See jimmy-skills@backend-go-naming skill for complete package naming conventions and examples.

Directory Layout

All main packages must reside in cmd/ with minimal logic — parse flags, wire dependencies, call Run(). Business logic belongs in internal/ or pkg/. Use internal/ for non-exported packages, pkg/ only when code is useful to external consumers.

Feature-First vs Layer-First (Recommended default for APIs: Feature-First)

For services beyond trivial size, prefer feature-first layout over layer-first. Group code by business capability, not by technical role:

# ❌ Layer-first — one feature scattered across 5+ folders
internal/
├── handlers/
│   ├── user_handler.go
│   └── invoice_handler.go
├── services/
│   ├── user_service.go
│   └── invoice_service.go
├── repository/
│   ├── user_repo.go
│   └── invoice_repo.go
└── models/
    ├── user.go
    └── invoice.go

# ✅ Feature-first — one feature lives in one place
internal/
├── users/
│   ├── handler.go
│   ├── service.go
│   ├── repository.go
│   ├── types.go
│   └── routes.go
├── invoices/
│   ├── handler.go
│   ├── service.go
│   ├── repository.go
│   └── types.go
└── shared/            # only when truly cross-cutting
    ├── middleware.go
    └── pagination.go

Why feature-first wins at scale:

  • Locality — modifying one feature means working mostly in one directory
  • Ownership — clear boundaries make team ownership and code review easier
  • Circular dependency prevention — features depend on shared code, not on each other
  • Incremental growth — start with one package, split into features when pain appears

Extra rule: shared packages stay small and boring. Create shared/, platform/, or common/ only for truly cross-cutting code, not as a dumping ground for every type used by more than one file.

Layer-first is not the default. In very small or short-lived services it may be tolerated briefly, but do not introduce technical-layer folders by reflex. Start with one package or feature packages, then split only when the code proves it needs the extra boundary.

Do not over-design too early. Start with fewer packages than you think you need. Split when pain appears, not before.

See directory layout examples for universal, small project, library, and feature-first layouts, plus common mistakes.

Essential Configuration Files

Every Go project should include at the root:

  • Makefile — build automation. See Makefile template
  • .gitignore — git ignore patterns. See .gitignore template
  • .golangci.yml — linter config. See the jimmy-skills@backend-go-linter skill for the recommended configuration

For application configuration with Cobra + Viper, see config reference.

Tests, Benchmarks, and Examples

Co-locate _test.go files with the code they test. Use testdata/ for fixtures. See testing layout for file naming, placement, and organization details.

Go Workspaces

Use go.work when developing multiple related modules in a monorepo. See workspaces for setup, structure, and commands.

Initialization Checklist

When starting a new Go project:

  • Ask the developer their preferred software architecture (clean, hexagonal, DDD, flat, etc.)
  • Ask the developer their preferred DI approach — manual wiring, google/wire, uber-go/dig+fx, or none
  • Decide project type (CLI, library, service, monorepo)
  • Right-size the structure to the project scope
  • Choose module name (matches repo URL, lowercase, hyphens)
  • Run go version to detect the current go version
  • Run go mod init github.com/user/project-name
  • Create cmd/{name}/main.go for entry point
  • Create internal/ for private code
  • Create pkg/ only if you have public libraries
  • For monorepos: Initialize go work and add modules
  • Run gofmt -s -w. to ensure formatting
  • Add .gitignore with /vendor/ and binary patterns

Circular Dependencies

Go enforces that package imports form a DAG — no cycles allowed. If package A imports B, then B cannot import A.

Why Go prohibits them: faster compilation, cleaner architecture, simpler maintenance.

Three solutions when you hit a cycle:

  1. Separate concerns — move the function to the package where it logically belongs (e.g., stock checking belongs in inventory, not product)
  2. Merge packages — if two packages are inseparably intertwined, consolidate them into one
  3. Use interfaces at the consumer side — define a small interface where you need it, inject the concrete implementation from main or a wiring package

Prevention:

  • Keep packages small and focused on one business capability (feature-first layout helps naturally)
  • Maintain one-way dependency direction across layers
  • If two features start depending on each other, extract the shared concept into a separate package or define consumer-side interfaces
  • Do not solve cycles by adding more technical-layer packages; that usually scatters one concern across more folders and worsens locality
  • If two packages are inseparable, merging them is often better than preserving a bad boundary

→ See jimmy-skills@backend-go-design-patterns for interface-based decoupling and dependency injection patterns.

Related Skills

→ See jimmy-skills@backend-go-cli skill for CLI tool structure and Cobra/Viper patterns. → See jimmy-skills@backend-go-linter skill for golangci-lint configuration. → See jimmy-skills@backend-go-continuous-integration skill for CI/CD pipeline setup. → See jimmy-skills@backend-go-design-patterns skill for architectural patterns.

适合场景

01

用户想查找某类 Agent Skill 时

02

需要根据任务场景推荐可安装能力包时

03

需要对比不同来源的安装命令和来源信息时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

保留来源站点、仓库和原始说明,方便继续核验

能力 4

展示第三方安全扫描或审计结果

安装后应在对应宿主中按原始 README 的触发条件使用;具体调用方式请以来源页面和 README 为准。

平台分布

Codex

36.31%
按下载量换算27

Claude

31.98%
按下载量换算24

Cursor

18.97%
按下载量换算14

Gemini CLI

9.53%
按下载量换算7

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

敏感数据

该 Skill 可能接触密钥、Token、环境变量或敏感配置,应进入高风险复核队列,默认不自动发布。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。当前只有一个来源,正式发布前建议补源仓库或其他目录站核验。

来源信息

继续浏览同类 Skills