Commit graph

10 commits

Author SHA1 Message Date
google-labs-jules[bot]
6339532d78 feat: Implement data binding, enhance HTML rendering, add context tests
This commit introduces several significant enhancements and completes key features:

1.  **Enhanced HTML Rendering:**
    - Defined a new `touka.HTMLRender` interface in `engine.go` for pluggable HTML rendering.
    - `Engine.HTMLRender` now uses this interface type.
    - `Context.HTML` is updated to use the configured `HTMLRender` instance, with improved error handling if no renderer is set or if rendering fails. The previous `fmt.Sprintf` fallback has been removed.
    - Added `DefaultHTMLRenderer` (using `html/template`) and helper methods `Engine.LoadHTMLGlob()` and `Engine.SetHTMLTemplate()` for easy setup.

2.  **Comprehensive Data Binding:**
    - **`Context.ShouldBindForm`**: Implemented using `gorilla/schema` to bind `x-www-form-urlencoded` and `multipart/form-data` (fields) from the request body.
    - **`Context.ShouldBindQuery`**: Implemented using `gorilla/schema` to bind URL query parameters.
    - **`Context.ShouldBindXML`**: Implemented using `encoding/xml` to bind XML data from the request body. This method also respects the `Engine.MaxRequestBodySize` limit.
    - **`Context.ShouldBind`**: Implemented as a generic binder that inspects the `Content-Type` header and dispatches to the appropriate specific binder (JSON, XML, Form). It handles missing or unsupported content types.

3.  **Comprehensive Unit Tests for `context.go`:**
    - Massively expanded `context_test.go` to provide extensive test coverage for nearly all methods in `context.go`.
    - This includes detailed tests for all new data binding methods, the updated HTML rendering logic, state management (`Keys`), request/response utilities, error handling, header and cookie manipulation, streaming, Go context integration, and logging.
    - Mocks for `HTMLRender`, `ErrorHandler`, and `reco.Logger` were used to facilitate thorough testing.

These changes significantly improve the framework's feature set, robustness, and maintainability due to increased test coverage.
2025-06-20 07:12:05 +00:00
wjqserver
57e92874d1 update deps 2025-06-12 10:02:33 +08:00
wjqserver
bb822599b9 update methods 2025-06-11 11:11:54 +08:00
wjqserver
96154fff78 update deps 2025-06-10 21:52:32 +08:00
wjqserver
e891afe0b4 remove ws, move to github.com/fenthope/ws 2025-06-09 23:18:15 +08:00
wjqserver
a4c22962ad update go version 2025-06-07 23:45:02 +08:00
wjqserver
899d3ff48b add logreco 2025-06-04 20:44:23 +08:00
wjqserver
dd4afc276b add auto websocket 2025-05-30 21:32:22 +08:00
wjqserver
4f0363a62f fix mod 2025-05-29 21:48:22 +08:00
wjqserver
484f2f016b init(v0.0.1) 2025-05-28 18:25:28 +08:00