🔥 feat: Add response format support to healthcheck middleware#4178
🔥 feat: Add response format support to healthcheck middleware#4178ReneWerner87 merged 6 commits intomainfrom
Conversation
- Add ResponseFormat type with constants for Text, JSON, XML, MsgPack, and CBOR - Update Config struct with ResponseFormat field (defaults to Text for backward compatibility) - Implement format-specific response handling in healthcheck middleware - Add comprehensive tests for all response formats - Update documentation with examples and usage notes Agent-Logs-Url: https://github.com/gofiber/fiber/sessions/9c742a5a-1106-4e9e-aef3-50cd4e5d3ee2 Co-authored-by: gaby <[email protected]>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4178 +/- ##
==========================================
+ Coverage 91.22% 91.23% +0.01%
==========================================
Files 123 123
Lines 11832 11847 +15
==========================================
+ Hits 10794 10809 +15
Misses 653 653
Partials 385 385
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
@claude[agent] The response format constants names are too verbose. |
- Rename ResponseFormatText -> FormatText - Rename ResponseFormatJSON -> FormatJSON - Rename ResponseFormatXML -> FormatXML - Rename ResponseFormatMsgPack -> FormatMsgPack - Rename ResponseFormatCBOR -> FormatCBOR - Update all references in code, tests, and documentation Agent-Logs-Url: https://github.com/gofiber/fiber/sessions/9ea6fcf4-ca4d-4353-8e6d-5a3131270d59 Co-authored-by: gaby <[email protected]>
Shortened the constant names to |
There was a problem hiding this comment.
Pull request overview
Adds configurable response formats to the healthcheck middleware so health endpoints can return plain text (default) or structured responses (JSON/XML/MsgPack/CBOR) with consistent semantics across success/failure.
Changes:
- Introduces
ResponseFormatconfig + constants to select output format. - Updates middleware handler to emit
{"status": ...}-style payloads for structured formats while preserving the text default. - Adds documentation and unit tests covering the new formats.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| middleware/healthcheck/healthcheck.go | Adds healthResponse struct and switches handler output based on configured response format. |
| middleware/healthcheck/config.go | Adds ResponseFormat type/field and format constants. |
| middleware/healthcheck/healthcheck_test.go | Adds new tests for each response format and header/status expectations. |
| docs/middleware/healthcheck.md | Documents response formats and required encoder setup for MsgPack/CBOR. |
|
@copilot apply changes based on the comments in this thread |
Agent-Logs-Url: https://github.com/gofiber/fiber/sessions/8452f509-11a4-4cea-9ff3-8bac52fa00d7 Co-authored-by: gaby <[email protected]>
Applied all three review suggestions in commit 7ee05cf:
|
|
@copilot apply changes based on the comments in this thread |
Agent-Logs-Url: https://github.com/gofiber/fiber/sessions/0c93520b-5e63-455a-9d73-5dc7ae7d45d8 Co-authored-by: gaby <[email protected]>
Applied the documentation fix in commit 0ee784f — added the missing Regarding the JSON test string comments (lines 291-294 and 302-305): those are already correct — the backtick raw string literals contain valid JSON without any backslash escaping, and the tests pass. No changes needed there. |
There was a problem hiding this comment.
⚠️ Performance Alert ⚠️
Possible performance regression was detected for benchmark.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 1.50.
| Benchmark suite | Current: 0ee784f | Previous: bf952a1 | Ratio |
|---|---|---|---|
Benchmark_Redirect_Route (github.com/gofiber/fiber/v3) |
283.2 ns/op 16 B/op 1 allocs/op |
174.4 ns/op 16 B/op 1 allocs/op |
1.62 |
Benchmark_Redirect_Route (github.com/gofiber/fiber/v3) - ns/op |
283.2 ns/op |
174.4 ns/op |
1.62 |
This comment was automatically generated by workflow using github-action-benchmark.
|
Congrats on merging your first pull request! 🎉 We here at Fiber are proud of you! If you need help or want to chat with us, join us on Discord https://gofiber.io/discord |
Description
The healthcheck middleware now supports multiple response formats (JSON, XML, MessagePack, CBOR) in addition to the default plain text format. This allows applications to maintain consistent API contracts across all endpoints, including health checks.
Changes introduced
New ResponseFormat configuration: Added
ResponseFormatfield toConfigwith 5 format options:FormatText(default, backward compatible)FormatJSONFormatXMLFormatMsgPackFormatCBORResponse structure: Introduced
healthResponsestruct that serializes consistently across all formats using proper struct tags (json,xml,msgpack,cbor) to ensure lowercase"status"key in all encodings:{"status":"OK"}(JSON example){"status":"Service Unavailable"}Documentation Update:
fiber/v3,middleware/healthcheck, encoder libraries)ResponseFormattype definition withiotaComprehensive test coverage: Added test cases for all 5 formats validating:
LivenessEndpointandReadinessEndpointconstants for consistency with the rest of the test suiteChangelog/What's New: Healthcheck middleware now supports configurable response formats (Text, JSON, XML, MsgPack, CBOR) while maintaining full backward compatibility.
API Longevity: The
ResponseFormatenum pattern provides extensibility for future formats without breaking changes. Default behavior (plain text) is unchanged, ensuring zero impact on existing deployments. Constant names follow Fiber's established naming conventions for brevity and clarity.Examples:
Type of change
Checklist
/docs/directory for Fiber's documentation.