Golang Api Server
ASecurityUse 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...
- 584 stars
- 0 votes
- 0 copies
- 4 views
- Added September 5, 2026
Security analysis
100/100Pro scans all 11 files and shows the line behind each finding
npx -y skills add HoangNguyen0403/agent-skills-standard --skill golang-api-server --agent claude-codeAre you the author of Golang Api Server?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/hoangnguyen0403-golang-api-server-agent-skills-standard)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.
Files in this skill
- eval-1.baseline.md
- eval-1.with-skill.md
- eval-2.baseline.md
- eval-2.with-skill.md
- eval-3.baseline.md
- eval-3.with-skill.md
- trigger-1.md
- trigger-2.md
- trigger-3.md
- trigger-4.md
Attribution
Related skills
View all in development →Comments
Loading comments…
Newsletter
Get the weekly list of safe new skills, and the ones we pulled.