feat: Add generic request binding and cool colored logger#8
Conversation
- Add BindJSON, BindQuery, BindForm to Context with comprehensive reflection support (floats, complex, slices, pointers). - Enhance Logger middleware with ANSI colors and structured output (Method, Path, Status, Latency). - Add tests for request binding and logger middleware.
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
- Add `Routes()` to `Router` interface and implement in `TrieRouter` for introspection. - Add validation tags (`required`, `min`, `max`) to `Bind*` methods. - Ensure `Bind*` methods safely handle non-pointer or nil inputs by returning errors. - Update `loggingResponseWriter` to implement `http.Flusher`. - Add comprehensive tests for validation, introspection, and binding safety.
- Add `addons/htmx` for HTMX helpers (Is, Trigger, Redirect, etc). - Enhance `Recovery` middleware with `WithHTMLDebug(bool)` option. - Add simple but pretty HTML template for panic debug page. - Verified with tests.
- Add `app.Test(req)` helper method to simplify integration testing for developers. - Removed Swagger UI addon based on user feedback. - Ensured all tests pass for new features (HTMX, Binding, Recovery).
This PR introduces two "cool" features to Amaro:
BindJSON,BindQuery, andBindFormhelper methods toContext. These methods use reflection to map request data (JSON body, query parameters, form data) directly to user-defined structs. The binding logic (bindData) supports a wide range of types including all integer/uint variants, floats, complex numbers, booleans, strings, pointers to these types, and slices of these types.Loggermiddleware to output visually distinct logs using ANSI colors. Status codes are color-coded (Green for 2xx, White for 3xx, Yellow for 4xx, Red for 5xx), and HTTP methods also get their own colors. The log format includes the status code, method, path, and latency.Tests were added for the new binding capabilities and the logger middleware was verified.
PR created automatically by Jules for task 6941033057768301019 started by @bernardoforcillo