Build production REST APIs with Go - handlers, middleware, security
View on GitHubpluginagentmarketplace/custom-plugin-go
go-development-assistant
January 21, 2026
Select agents to install to:
npx add-skill https://github.com/pluginagentmarketplace/custom-plugin-go/blob/main/skills/go-web-apis/SKILL.md -a claude-code --skill go-web-apisInstallation paths:
.claude/skills/go-web-apis/# Go Web APIs Skill
Build production-ready REST APIs with Go's net/http and popular frameworks.
## Overview
Complete guide for building secure, performant web APIs including routing, middleware, authentication, and best practices.
## Parameters
| Parameter | Type | Required | Default | Description |
|-----------|------|----------|---------|-------------|
| framework | string | no | "stdlib" | Framework: "stdlib", "gin", "echo", "chi" |
| auth_type | string | no | "jwt" | Auth method: "jwt", "api-key", "oauth" |
| include_openapi | bool | no | false | Generate OpenAPI spec |
## Core Topics
### HTTP Handler Pattern
```go
type Server struct {
db *sql.DB
logger *slog.Logger
}
func (s *Server) handleGetUser() http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
id := chi.URLParam(r, "id")
user, err := s.db.GetUser(r.Context(), id)
if err != nil {
if errors.Is(err, sql.ErrNoRows) {
http.Error(w, "user not found", http.StatusNotFound)
return
}
s.logger.Error("get user", "error", err)
http.Error(w, "internal error", http.StatusInternalServerError)
return
}
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(user)
}
}
```
### Middleware
```go
func LoggingMiddleware(logger *slog.Logger) func(http.Handler) http.Handler {
return func(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
start := time.Now()
ww := &responseWriter{ResponseWriter: w, status: 200}
defer func() {
logger.Info("request",
"method", r.Method,
"path", r.URL.Path,
"status", ww.status,
"duration", time.Since(start),
)
}()
next.ServeHTTP(ww, r)
})
}
}