MCP HubMCP Hub
SKILL·93AC90

go-project-layout

eduardo-sl
업데이트됨 22 days ago
5 조회
68
9
68
GitHub에서 보기
메타ai

정보

이 스킬은 프로젝트 규모에 적합한 디렉토리 구조와 규칙을 따라 새로운 Go 프로젝트의 기반을 구성합니다. 개발자가 평면 레이아웃과 cmd/ 및 internal/ 디렉토리를 포함한 구조적 접근 방식 중 선택할 수 있도록 도와주며, 모듈 명명과 메인 패키지 연결 방법을 다룹니다. 새로운 Go 모듈이나 서비스를 시작할 때 사용하되, 기존 아키텍처 검토나 상세한 의존성 주입에는 적합하지 않습니다.

빠른 설치

Claude Code

추천
기본
npx skills add eduardo-sl/go-agent-skills -a claude-code
플러그인 명령대체
/plugin add https://github.com/eduardo-sl/go-agent-skills
Git 클론대체
git clone https://github.com/eduardo-sl/go-agent-skills.git ~/.claude/skills/go-project-layout

Claude Code에서 이 명령을 복사하여 붙여넣어 스킬을 설치하세요

문서

Go Project Layout

Structure follows size. The biggest layout mistake in Go is copying a microservice skeleton for a 500-line tool — or growing a 50-package service inside a flat directory. Match the layout to the project.

1. Pick the Layout by Project Size

ProjectLayout
Small tool, single binary, <5 filesFlat: everything in package main at the root
Library for others to importRoot package named after the module, internal/ for helpers
Service with one binarycmd/<name>/main.go + internal/ packages
Multiple binaries sharing codecmd/<name1>/, cmd/<name2>/ + internal/

Never start with empty pkg/, api/, docs/, build/ directories "for later". Add structure when the code demands it, not before.

2. Module Naming

# ✅ Good — repository path, lowercase
go mod init github.com/acme/payment-service

# ❌ Bad — not fetchable, uppercase, or vanity without DNS
go mod init PaymentService
go mod init payment_service

The last path element should match what users will see: for a library, it becomes the default import name.

3. Service Layout (the default for APIs and workers)

payment-service/
├── cmd/
│   └── payment-api/
│       └── main.go         # flag/env parsing, wiring, Run() — nothing else
├── internal/
│   ├── domain/             # core types, business rules; zero external deps
│   ├── service/            # use cases orchestrating domain + stores
│   ├── store/              # data access implementations (postgres/, redis/)
│   ├── handler/            # HTTP/gRPC adapters
│   └── config/             # config loading and validation
├── migrations/             # if the service owns a database
├── go.mod
├── Makefile
└── README.md

Rules:

  • internal/ by default — the compiler enforces that nobody outside the module imports it. Promote to a public package only on demand.
  • pkg/ only when external consumers exist AND the module also has private code. When in doubt, don't create it.
  • Dependencies point inward: handler → service → domain ← store. domain imports neither store nor handler.

4. Thin main, Runnable Run

Keep main.go to wiring plus a delegating call, so the app is testable:

func main() {
    if err := run(context.Background(), os.Args[1:], os.Getenv); err != nil {
        fmt.Fprintln(os.Stderr, err)
        os.Exit(1)
    }
}

func run(ctx context.Context, args []string, getenv func(string) string) error {
    cfg, err := config.Load(getenv)
    if err != nil {
        return fmt.Errorf("load config: %w", err)
    }

    db, err := store.Open(ctx, cfg.DatabaseURL)
    if err != nil {
        return fmt.Errorf("open db: %w", err)
    }
    defer db.Close()

    svc := service.New(store.NewUserRepo(db))
    srv := handler.NewServer(cfg.Addr, svc)
    return srv.ListenAndServe(ctx)
}
  • os.Exit appears exactly once, in main.
  • run takes its dependencies (args, getenv) so tests can call it.
  • No init() functions for wiring — explicit construction order only.

5. Library Layout

retry/
├── retry.go            # package retry — the API, in the root
├── retry_test.go
├── backoff.go          # same package, split by topic
├── internal/
│   └── clock/          # implementation details users must not import
├── examples_test.go    # Example* functions shown in godoc
└── go.mod
  • The root directory IS the package. No src/, no lib/.
  • One package per concept. Resist util, common, helpers — name packages after what they provide (retry, clock, httpsign).

6. Naming Rules for Directories and Packages

  • Package name == directory name, short, lowercase, no underscores: store/postgres, not store/postgres_impl.
  • Don't stutter: payment.Service, not payment.PaymentService.
  • Binary names in cmd/ are user-facing: cmd/payment-api, hyphenated is fine (directory only holds package main).

7. Files That Belong at the Root

  • go.mod, go.sum, README.md, LICENSE, Makefile, .golangci.yml, Dockerfile (single-binary projects).
  • Do NOT create: src/ (un-idiomatic), vendor/ (unless the team explicitly vendors), one-file packages like types/ or models/ that become dumping grounds.

Scaffolding Procedure

  1. Ask/decide: tool, library, or service? How many binaries?
  2. go mod init <repo-path>.
  3. Create only the directories the first feature needs.
  4. Write main.go with the thin-main pattern above.
  5. Add Makefile targets: build, test, lint.
  6. Verify: go build ./... and go vet ./... pass on the skeleton.

Verification Checklist

  1. Layout matches project size — no empty scaffolding directories
  2. Module path is the fetchable repository path
  3. All non-public packages live under internal/
  4. main.go is thin: parse, wire, call run, exit
  5. os.Exit only in main; no wiring in init()
  6. Dependencies flow inward; domain has zero infrastructure imports
  7. No util/common/helpers/models grab-bag packages
  8. Package names match directories, lowercase, no stutter
  9. go build ./... passes on the fresh skeleton

GitHub 저장소

eduardo-sl/go-agent-skills
경로: skills/(architecture)/go-project-layout
0
FAQ

자주 묻는 질문

go-project-layout Skill이란 무엇인가요?

go-project-layout은(는) eduardo-sl이(가) 만든 Claude Skill입니다. Skill은 Claude가 필요할 때 불러오는 지침과 리소스를 묶어 추가 프롬프트 없이 go-project-layout 관련 작업을 수행할 수 있게 합니다.

go-project-layout은(는) 어떻게 설치하나요?

이 페이지의 설치 명령을 사용하세요. go-project-layout을(를) Claude Code 플러그인으로 추가하거나 저장소를 skills 디렉터리에 복제한 다음 Claude를 다시 시작해 Skill을 불러옵니다.

go-project-layout은(는) 어떤 카테고리에 속하나요?

go-project-layout은(는) 메타 카테고리에 속합니다.

go-project-layout은(는) 무료로 사용할 수 있나요?

네. go-project-layout은(는) AIMCP에 등록되어 있으며 무료로 설치할 수 있습니다.

연관 스킬

content-collections
메타

이 스킬은 콘텐츠 콜렉션(Content Collections)을 위한 프로덕션 검증된 설정을 제공합니다. 콘텐츠 콜렉션은 Markdown/MDX 파일을 Zod 검증이 포함된 타입 안전한 데이터 콜렉션으로 변환해주는 TypeScript 최우선 도구입니다. 블로그, 문서 사이트 또는 콘텐츠 중심의 Vite + React 애플리케이션을 구축할 때 타입 안전성과 자동 콘텐츠 검증을 보장하기 위해 사용하세요. Vite 플러그인 구성과 MDX 컴파일부터 배포 최적화 및 스키마 검증에 이르기까지 모든 것을 다룹니다.

스킬 보기
polymarket
메타

이 스킬은 개발자들이 Polymarket 예측 시장 플랫폼을 활용한 애플리케이션을 구축할 수 있도록 지원하며, 거래 및 시장 데이터를 위한 API 통합 기능을 포함합니다. 또한 WebSocket을 통한 실시간 데이터 스트리밍을 제공하여 실시간 거래와 시장 활동을 모니터링할 수 있습니다. 이를 통해 거래 전략을 구현하거나 실시간 시장 업데이트를 처리하는 도구를 생성하는 데 활용할 수 있습니다.

스킬 보기
creating-opencode-plugins
메타

이 스킬은 개발자들이 명령어, 파일, LSP 작업 등 25개 이상의 이벤트 유형에 연결되는 OpenCode 플러그인을 만들 수 있도록 돕습니다. JavaScript/TypeScript 모듈을 위한 플러그인 구조, 이벤트 API 명세, 구현 패턴을 제공합니다. OpenCode AI 어시스턴트의 라이프사이클을 사용자 정의 이벤트 기반 로직으로 가로채거나, 모니터링하거나, 확장해야 할 때 사용하세요.

스킬 보기
sglang
메타

SGLang은 RadixAttention 프리픽스 캐싱을 활용하여 JSON, 정규식, 에이전트 워크플로우를 위한 고속 구조화 생성에 특화된 고성능 LLM 서빙 프레임워크입니다. 특히 반복되는 프리픽스가 있는 작업에서 상당히 빠른 추론 속도를 제공하여 복잡한 구조화 출력 및 다중 턴 대화에 이상적입니다. 제약 디코딩이 필요하거나 광범위한 프리픽스 공유가 있는 애플리케이션을 구축할 때는 vLLM과 같은 대안보다 SGLang을 선택하십시오.

스킬 보기