Use a thin HTTP handler for `POST /orders`: require JSON, bind and validate the request, call an injected `OrderService`, map service errors to HTTP responses, and return the created order as JSON. Business rules such as pricing, stock checks, and order creation belong in the service or domain layer, not in the handler. ```go type OrderHandler struct { service OrderService } func (h *OrderHandler) Create(c echo.Context) error { if c.Request().Header.Get(echo.HeaderContentType) != "application...
Scanned 9/5/2026
Install to Claude Code
npx -y skills add HoangNguyen0403/agent-skills-standard --skill golang-api-server --agent claude-codeInstalls into .claude/skills of the current project.
Are you the author of Golang Api Server?
Add the live security badge to your README — it updates automatically with every re-scan.
[](https://www.skillsdirectory.com/skills/hoangnguyen0403-golang-api-server-agent-skills-standard)More formats (shields.io, HTML) on the badges page.
Use a thin HTTP handler for `POST /orders`: require JSON, bind and validate the request, call an injected `OrderService`, map service errors to HTTP responses, and return the created order as JSON. Business rules such as pricing, stock checks, and order creation belong in the service or domain layer, not in the handler.
```go
type OrderHandler struct {
service OrderService
}
func (h *OrderHandler) Create(c echo.Context) error {
if c.Request().Header.Get(echo.HeaderContentType) != "application/json" {
return echo.NewHTTPError(http.StatusUnsupportedMediaType, "content type must be application/json")
}
var req CreateOrderRequest
if err := c.Bind(&req); err != nil {
return echo.NewHTTPError(http.StatusBadRequest, "invalid request")
}
if err := validate(req); err != nil {
return echo.NewHTTPError(http.StatusBadRequest, err.Error())
}
order, err := h.service.Create(c.Request().Context(), req)
if err != nil {
return mapOrderError(err)
}
return c.JSON(http.StatusCreated, order)
}
```
Construct the handler with the service during application setup and register it on the router. Keep middleware such as logging, recovery, auth, and tracing at the router boundary; the handler should parse, delegate, and format the response only.
Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.
No comments yet. Be the first to comment!