hieudoanm/hieudoanm.github.io/echo
Claude Code and agent skill by hieudoanm/hieudoanm.github.io
- community
Checking that the SKILL.md file is still in the repository.
Best practices for building Go web services with Echo — the high-performance HTTP framework conventions. Use when writing, structuring, or reviewing Echo — covers routing, middleware, handlers, context, validation, errors, testing, and deployment.
Install
npx vskill@latest install hieudoanm/hieudoanm.github.io/echoSKILL.md
The same SKILL.md was published earlier as hieudoanm/hieudoanm.github.io/echo.
Echo Best Practices
Echo is a high-performance Go web framework with a rich ecosystem of middleware and an elegant handler signature func(c echo.Context) error that centralizes request/response handling. Practical Echo leans on route groups with layered middleware, one handler per request concern, a `Context`-owned request boundary that flows cancellation downstream, and errors returned, not thrown, with a uniform error handler.
1. Route Grouping
- `echo.New()` at the entry; `Group` for middleware scope:
- Subroutes per domain (
r.Group("/users", ...)orrouter.GET); the path contract visible at the route definition. - `e.GET`/`e.POST`/`e.DELETE` at the top level; `Group` only where middleware scoping matters.
- `e.HTTPErrorHandler` set once — global error-to-response mapping, not per-handler
c.JSONcalls.
2. Middleware
- Middleware is a function wrapping the handler; order matters (Logger → Recoverer → CORS → Auth → business):
- Echo's built-in middleware (
Logger,Recover,Gzip,CORS) are the defaults; custom ones follow the same signature. - Auth middleware on the protected group — never per-route; the group is the security domain.
- Middleware returns error — an auth failure can
return echo.ErrUnauthorizedinstead of swallowing the failure silently. - Request-id before logging/auth — spans carry the identity; the logger writes the ID out.
3. Handlers
- Handler returns `error` — the framework renders it; the handler owns the domain:
- One concern per handler — parse, validate, call service, return.
- No business logic in handlers — handlers are HTTP adapters, not domain containers.
- Error returned; no `c.JSON(err)` in every handler — the global error handler maps error → JSON shape.
- Validation at the boundary before any service call — use Echo's validator or
go-playground/validatorvia struct tags.
4. Context & Binding
- `c.Bind(&input)` for request binding/validation — JSON, query, form, multipart; the framework does the work:
- `c.Set`/`c.Get` for request-scoped values (request-id, user-id) — keep it minimal; don't store entire services in context.
- Context cancellation flows downstream (
c.Request().Context()) to DB/HTTP calls; the handler owns the deadline. - `echo.Map` for ad-hoc JSON; typed structs for all API boundaries.
5. Error Handling
- Return errors from handlers; the global `HTTPErrorHandler` shapes them:
- Domain errors converted to `echo.HTTPError` at the repo/service boundary — a named mapping function over error type.
- No panics as control flow —
Recoverercatches them, but the contract says "return error". - Safe messages out — internal detail to logs; a generic shape to the client.
6. Testing
- Handler tests via `httptest` + the full router — a real HTTP request, not a fake:
- Fakes at the service/repo boundary — the handler test owns the HTTP layer; service test owns domain logic.
- Integration tests via `httptest.NewServer` for real network round-trips.
- Contract cases: valid, invalid, not-found, unauthorized, method-not-allowed.
General Rules of Thumb
- Route groups scope middleware; middleware order is the request-processing pipeline.
- Handler returns `error`; the global error handler maps domain → HTTP response.
- Validate at the boundary; bind via `c.Bind`; context carries the request down.
- Handlers are thin adapters; business logic lives in services.
- Tests via `httptest` + full router; contract covered.
Quick-Start Checklist
- [ ]
Groupper domain; middleware ordered (Logger → Recover → CORS → Auth) - [ ] Handler returns
error;echo.HTTPErrorfor boundary conversions - [ ]
c.Bindat entry; validation before any mutation;c.Request().Context()down - [ ] Domain errors converted to
HTTPErrorin a shared mapper - [ ]
echo.HTTPErrorHandlerset once; JSON error response shape uniform - [ ] No panic-as-control-flow;
Recovererfor the unexpected - [ ]
httptesthandler tests + contract; service/repo fakes in unit tests
Security
- Security scanPassed, 90 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryChecking.skills/programming/languages/go/backend/echo/SKILL.md
Popularity
- 7-day trend score
- 0
Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/hieudoanm/hieudoanm.github.io/echo)