Skip to content

feat: add /health endpoint and HTTP server#12

Merged
Lewiskunta merged 1 commit into
mainfrom
feat/health-endpoint
May 30, 2026
Merged

feat: add /health endpoint and HTTP server#12
Lewiskunta merged 1 commit into
mainfrom
feat/health-endpoint

Conversation

@Lewiskunta

Copy link
Copy Markdown
Contributor

Implements: /health endpoint and HTTP server startup.

Changes:

  • Installed github.com/go-chi/chi/v5 and github.com/jackc/pgx/v5
  • Created internal/db/db.go - connection pool helper using pgxpool
  • Created internal/api/router.go - Chi router with Logger and
    Recoverer middleware
  • Created internal/api/health.go - GET /health handler
    • Returns HTTP 200 with {"status":"ok","database":"ok",...}
    • Returns HTTP 503 with {"status":"degraded","database":"unreachable",...}
    • 3-second database ping timeout prevents hanging health checks
  • Replaced cmd/server/main.go placeholder with real HTTP server
    • Configurable read/write/idle timeouts
    • Graceful shutdown on SIGINT/SIGTERM with 30-second drain period
  • Tests for health response structure and statusFromHTTP helper

Verified manually:

  • GET /health returns 200 when postgres is running
  • GET /health returns 503 when postgres is stopped
  • Server shuts down cleanly on Ctrl+C

@Lewiskunta Lewiskunta merged commit 89730b4 into main May 30, 2026
4 checks passed
@Lewiskunta Lewiskunta deleted the feat/health-endpoint branch May 30, 2026 14:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant