CLAUDE.md

CLAUDE.md cho dự án Go

Chỉ dẫn cho Claude về cách build, test, kiểm tra code và xử lý lỗi theo phong cách Go. Phù hợp dịch vụ backend hoặc công cụ dòng lệnh viết bằng Go.

Đã thử với Claude Code 2.1.329

Chỗ cần điền

  • {{project_name}}Tên dự ánví dụ ledger
  • {{module_path}}Đường dẫn module trong go.modví dụ github.com/acme/ledger
CLAUDE.md
# {{project_name}}

Go module `{{module_path}}`.

## Commands
- Build: `go build ./...`
- Test all: `go test ./...`
- Test one package with the race detector: `go test -race ./internal/store/...`
- Vet and lint: `go vet ./... && golangci-lint run`
- Format: `gofmt -w .` (done automatically by most editors; still run it)

Run build, vet and the tests of the packages you touched before saying a task is done.

## Layout
- `cmd/<name>/main.go`: entry points only, no logic.
- `internal/`: application code, not importable from outside the module.
- Table-driven tests in `*_test.go` next to the code.

## Conventions
- Return errors, do not panic; wrap with `fmt.Errorf("doing x: %w", err)`.
- Pass `context.Context` as the first argument to anything that does I/O.
- Keep interfaces small and define them where they are used.
- No global mutable state; inject dependencies through constructors.

## Do not
- Edit generated files (`*.pb.go`, `*_gen.go`); change the source and regenerate.
- Add a module without explaining why; run `go mod tidy` after any change.

Bài học liên quan

Gõ để tìm trong tra cứu, mẫu cấu hình và bài học. Không dấu cũng được.