1.1 KiB
1.1 KiB
Skill: Go project patterns
New endpoint checklist
- Define request/response types in
types.go - Write handler in
handlers.gousinghttp.HandlerFunc - Add route in
routes.go - Write table-driven test in
handlers_test.go - Run
task checkbefore committing
Error handling pattern
if err != nil {
return fmt.Errorf("descriptiveOperation: %w", err)
}
Never log and return — do one or the other.
HTMX response pattern
func (h *Handler) ListItems(w http.ResponseWriter, r *http.Request) {
items, err := h.store.List(r.Context())
if err != nil {
http.Error(w, "failed to list items", http.StatusInternalServerError)
return
}
if r.Header.Get("HX-Request") == "true" {
h.templates.Render(w, "items/_list", items)
return
}
h.templates.Render(w, "items/index", items)
}
Dependency policy
- Prefer stdlib:
net/http,encoding/json,database/sql - Allowed without justification:
testify,slog,templ,sqlc - Needs justification in commit message: anything else