- Home
- Skills
- APIs & Backend
- Go API Services: Idiomatic, Tested, Production Go
Go API Services: Idiomatic, Tested, Production Go
by Ignasi
Build and review idiomatic, production-grade Go services with structured logging, sqlc, and safe concurrency.
Free
Go API Services: Idiomatic, Tested, Production Go
Example session with this skill installed
Build a Go 1.22 REST API for a simple inventory service. I need a GET endpoint for items by ID and a POST endpoint. Use sqlc for the database and slog for logging.
- Read your context and instructions
- Compiled the go api services
I have scaffolded the inventory service using idiomatic Go 1.22 patterns. The implementation includes structured logging, context-aware database operations, and a production-ready project layout.
Inventory Service Implementation
Project Layout
cmd/api/main.go: Entry point with graceful shutdown and dependency injection.internal/http/handler.go: HTTP handlers using Go 1.22 path routing.internal/store/db.go: Data access layer designed for sqlc integration.
Implementation Code
// internal/http/handler.go
package http
import (
"encoding/json"
"log/slog"
"net/http"
)
type ItemStore interface {
GetItem(ctx context.Context, id string) (Item, error)
CreateItem(ctx context.Context, item Item) error
}
func RegisterRoutes(mux *http.ServeMux, store ItemStore, logger *slog.Logger) {
mux.HandleFunc("GET /items/{id}", handleGetItem(store, logger))
mux.HandleFunc("POST /items", handleCreateItem(store, logger))
}
func handleGetItem(s ItemStore, l *slog.Logger) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
id := r.PathValue("id")
item, err := s.GetItem(r.Context(), id)
if err != nil {
l.Error("failed to get item", slog.String("id", id), slog.Any("error", err))
http.Error(w, "item not found", http.StatusNotFound)
return
}
json.NewEncoder(w).Encode(item)
}
}
func handleCreateItem(s ItemStore, l *slog.Logger) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var item Item
if err := json.NewDecoder(http.MaxBytesReader(w, r.Body, 1048576)).Decode(&item); err != nil {
http.Error(w, "bad request", http.StatusBadRequest)
return
}
if err := s.CreateItem(r.Context(), item); err != nil {
l.Error("creation failed", slog.Any("error", err))
http.Error(w, "internal error", http.StatusInternalServerError)
return
}
w.WriteHeader(http.StatusCreated)
}
}
Next steps
- Run
sqlc generateto create the type-safe models for theinternal/storepackage. - Configure environment variables for
PGURLandPORTbefore starting the server. - Use the provided
Dockerfileto build the static, non-root container image.
Connects securely to your tools. The creator never sees your data.
About this skill
Standardize your Go microservices with idiomatic patterns that prioritize observability and reliability. This skill addresses the common pitfalls of Go development, such as goroutine leaks, improper error handling, and fragile project structures that become unmaintainable as they scale.
What it does
- Architects project layouts using a clean
cmd/andinternal/structure to prevent circular dependencies. - Implements robust IO with strict
context.Contextpropagation, timeouts, and graceful shutdown sequences. - Enforces error handling through structured wrapping with
errors.Is/Asand centralized HTTP status mapping. - Secures data access using
sqlcfor type-safe queries andpgxpoolfor efficient PostgreSQL connection management. - Optimizes concurrency via
errgroupfor bounded parallelism and race-free state management.
How it works
- Scaffold or Review: Provide a requirement for a new service or existing code for a performance and idiom audit.
- Logic Implementation: The skill generates business logic in
internal/service/and data access ininternal/store/. - Infrastructure Wiring: It configures
slogJSON logging, environment validation, and Go 1.22+ routing. - Validation: It produces table-driven tests and Docker multi-stage builds for deployment.
Frameworks & tools
Go 1.22+, net/http, chi, echo, gin, pgx, sqlc, log/slog, goose, atlas, testcontainers, and golangci-lint.
Why this beats prompting it yourself
Generic prompts often produce "Java-in-Go" patterns or ignore critical production details like MaxBytesReader and ReadHeaderTimeout. This skill embeds specific Go 1.22 routing conventions and strict concurrency safety checks that prevent runtime data races and memory leaks.
Use cases
- Building a high-performance REST API with PostgreSQL.
- Refactoring a monolithic main.go into a clean, testable internal structure.
- Auditing existing services for goroutine leaks and missing context cancellations.
- Setting up a CI-ready Go project with linting and multi-stage Dockerfiles.
Known limitations
Focuses on PostgreSQL via pgx; other drivers may require manual adjustment. OpenTelemetry integration is optional and basic.
How to use
- 1
Connect your agent to the Agensi MCP
Copy the prompt and paste it into Claude, ChatGPT, Cursor or any agent that supports MCP. It sets up the connection for you. Manual setup
- 2
Sign in to Agensi
Your agent shows a sign-in link. Sign in and click Allow.
- 3
Ask for what you need
Your agent loads this skill and uses it on your task. It always asks before buying a skill.
Reviews
No reviews yet
Be one of the first to try it. Every listed skill goes through the trust checks below.
Security scanned
Checked by our 8-point scan before listing
1 use
Times used to date
Free to use
No account required to browse
Trust & safety
Security scan
Security scan passed 11 days ago
- Free with an Agensi account
Permissions
What's inside
Frequently Asked Questions
New in APIs & Backend
Find more skills like this on the Claude Skills Marketplace, the Codex Skills Marketplace and the Gemini Skills Marketplace, or browse Claude Skills for APIs & Backend.