1---2name: backend-golang3description: Build, maintain, and debug Go backends (Gin and Echo).4---56# Backend - Go (Gin/Echo)78## When to use this skill9- Building or updating Go HTTP APIs using Gin or Echo.10- Adding routes/handlers/middleware, validation, logging, or persistence.11- Improving performance, observability, security, or testing for Go services.1213## Quick start141. Install deps: `go mod tidy` (or `go mod download`).152. Env: copy `.env.example` -> `.env` if present; load via `godotenv`/config; set DB URLs, secrets, and service endpoints.163. Run: `go run ./...` or service-specific `make dev` if provided.174. Test: `go test ./...`; lint/format: `golangci-lint run` and `gofmt -w`/`go fmt ./...`.185. Build: `go build ./cmd/...` or project entry.1920## Project structure basics21- `cmd/<service>/main.go`: entrypoint; wire router, middleware, config, logger, DI.22- `internal/` or `pkg/`: handlers, services/usecases, repositories, domain models, DTOs.23- `configs/`: config files; prefer typed config structs with validation.24- `migrations/`: SQL/DDL migrations if applicable.2526## Coding principles27- Keep handlers thin: parse/validate input, call services/usecases, map errors to HTTP responses.28- Services hold business logic; repositories isolate data access; prefer interfaces for tests.29- Validate inputs; return typed errors and map to consistent JSON error shapes.30- Use context-aware logging with request IDs; never log secrets.31- Prefer `golangci-lint` and `go test ./...` before merge (see scripts/dev-check.sh).3233## Patterns and snippets34- See references/snippets.md for Gin/Echo router setup, middleware, handlers, error mapping, and DI patterns.35- Centralize HTTP error responses; include correlation ID; avoid panics in request path.36- Use `context.Context` in all public methods; pass through layers.3738## Bundled resources39- scripts/dev-check.sh: run pre-commit/PR to enforce gofmt, lint, tests, and optional build.40- references/coding-standards.md: guardrails on layering, validation, errors, logging, and testing.41- references/best-practices.md: deeper guidance for Gin/Echo routing, middleware, observability, performance, and security.42- references/snippets.md: ready-to-copy snippets for Gin and Echo (routing, middleware, handlers, errors).43- assets/pr-template.md: PR checklist with testing evidence and API notes.44- assets/migration-checklist.md: use when adding DB schema changes.4546## Delivery checklist47- `gofmt`/`go fmt` clean; `golangci-lint run` passes; `go test ./...` green.48- Config validated; secrets not logged; env vars documented.49- HTTP errors normalized; correlation/request IDs propagated.50- Migrations applied/documented if DB changes; API contracts/docs updated if endpoints change.