Tags: alexferl/zerohttp
Tags
feat(zhtest): add AnError sentinel and AssertWithin assertion (#176) Add `AnError` sentinel error for mock return values and `AssertWithin` for floating-point range assertions. Includes tests for both and a nolint directive for the non-standard error variable name. Signed-off-by: alexferl <me@alexferl.com>
fix: remove busy-wait loop in server startup select (#174) The for-select around errCh/startupHookErrCh would spin when channels closed or delivered zero values. Replace with a single select that blocks on both channels deterministically. Signed-off-by: alexferl <me@alexferl.com>
feat: return 422 for unknown JSON fields and include safe bind error … …details (#173) Unknown fields from DisallowUnknownFields now return 422 Unprocessable Entity with the field name in the errors response: {"field": ["extra inputs are not permitted"]} Invalid JSON syntax still returns 400 Bad Request, and now includes the actual syntax error detail safely without leaking struct internals. Also fixes all reflect.Ptr -> reflect.Pointer occurrences to satisfy the inline linter check. Signed-off-by: alexferl <me@alexferl.com>
fix: validator had a bug where required on pointer fields was applied… … twice - once to check the pointer was non-nil (correct), and again on the dereferenced value (incorrect). So *float64 pointing to 0 (#172) failed because 0 is the zero value for float64. Signed-off-by: alexferl <me@alexferl.com>
feat(sse): add context.Context to Broadcaster interface methods (#171) All Broadcaster methods — Register, Unregister, Subscribe, Unsubscribe, Broadcast, and BroadcastTo — now accept a context.Context as their first parameter. Updated implementations, tests, benchmarks, examples, and documentation accordingly. Signed-off-by: alexferl <me@alexferl.com>
feat(sse): add Broadcaster interface and broadcast hooks (#170) - Introduce Broadcaster interface for pluggable hub implementations - Add OnBroadcast and OnBroadcastTo hooks to Hub for observability - Update tests and package docs Signed-off-by: alexferl <me@alexferl.com>
feat: default error responses to JSON instead of plain text (#169) Change the default behavior when no Accept header is present to return application/problem+json instead of text/plain. This affects: - All middleware error responses (circuitbreaker, cors, csrf, host, idempotency, jwtauth, ratelimit, recover, timeout) - Router default 404 Not Found and 405 Method Not Allowed handlers The AcceptsJSON() function now returns true when the Accept header is empty, making JSON the default response format. Clients can still request plain text by sending Accept: text/plain. Updated all tests to reflect the new default behavior and added explicit tests for plain text responses when requested. Signed-off-by: alexferl <me@alexferl.com>
feat(pagination): make defaults configurable (#168) Add `DefaultPerPage` (25) and `DefaultMaxPerPage` (100) package-level variables that can be changed at runtime to configure pagination defaults. BREAKING CHANGE: Default per_page changed from 20 to 25. Signed-off-by: alexferl <me@alexferl.com>
feat(mediatype): add ResponseTypeFunc for dynamic response headers (#167 ) Replace static ResponseTypeValue with ResponseTypeFunc that transforms the negotiated media type into the response header value. This enables the header to reflect what was actually negotiated (e.g., app.v2 when client requests v2) rather than a static construction-time value. Changes: - Config.ResponseTypeValue → Config.ResponseTypeFunc func(string) string - Compute effective type at request time based on matched Accept header - Add VendorShortType helper: "application/vnd.app.v1+json" -> "app.v1" - Add findMatchingType to determine which allowed type matched Signed-off-by: alexferl <me@alexferl.com>
PreviousNext