henriqueatila/golang-gin-best-practices / skills/golang-gin-architect
golang-gin-architect
VerifiedSoftware architect for Go Gin APIs. Use when making architecture decisions, evaluating complexity, designing systems, choosing patterns, or coordinating across gin skills.
references/cross-cutting-health-checks.md
View on GitHub# Cross-Cutting Concerns — Health Checks
Liveness and readiness endpoints for Go Gin APIs.
Companion to `cross-cutting-observability.md` (logging, metrics, tracing).
---
## Health Check Handler
```go
type HealthChecker struct {
db *sqlx.DB
redis *redis.Client // optional
}
func (h *HealthChecker) Liveness(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{"status": "alive"})
}
func (h *HealthChecker) Readiness(c *gin.Context) {
ctx, cancel := context.WithTimeout(c.Request.Context(), 2*time.Second)
defer cancel()
checks := gin.H{"status": "ready"}
if err := h.db.PingContext(ctx); err != nil {
checks["status"] = "not_ready"
checks["db"] = err.Error()
c.JSON(http.StatusServiceUnavailable, checks)
return
}
checks["db"] = "ok"
if h.redis != nil {
if err := h.redis.Ping(ctx).Err(); err != nil {
checks["status"] = "not_ready"
checks["redis"] = err.Error()
c.JSON(http.StatusServiceUnavailable, checks)
return
}
checks["redis"] = "ok"
}
c.JSON(http.StatusOK, checks)
}
r.GET("/health/live", health.Liveness)
r.GET("/health/ready", health.Readiness)
```
---
## Liveness vs Readiness
| Endpoint | Purpose | Kubernetes probe |
|---|---|---|
| `/health/live` | Is the process alive? Restart if fails. | `livenessProbe` |
| `/health/ready` | Can the service handle traffic? Remove from load balancer if fails. | `readinessProbe` |
**Liveness:** Never check external dependencies (DB, Redis). Only check if the process itself is healthy (not deadlocked).
**Readiness:** Check critical dependencies. If DB is unreachable, return 503 — Kubernetes stops routing traffic until DB recovers.
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| brainstormingobra/superpowersYou MUST use this before any creative work - creating features, building components, adding functionality, modifying behavior, or planning anything new, in software or out of it (a talk, a business, a renovation). | Stars: 323k | Updated | Claude CodeCodex | Verified | Install |
| brand-guidelinesanthropics/skillsApplies Anthropic's official brand colors and typography to any sort of artifact that may benefit from having Anthropic's look-and-feel. Use it when brand colors or style guidelines, visual formatting, or company design standards apply. | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |
| frontend-designanthropics/skillsGuidance for distinctive, intentional visual design when building new UI or reshaping an existing one. Helps with aesthetic direction, typography, and making choices that don't read as templated defaults. | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |
| mcp-builderanthropics/skillsGuide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when building MCP servers to integrate external APIs or services, whether in Python (FastMCP) or Node/TypeScript (MCP SDK). | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |