touka/go.mod
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

15 lines
373 B
Modula-2

module github.com/infinite-iroha/touka
go 1.24.4
require (
github.com/WJQSERVER-STUDIO/go-utils/copyb v0.0.4
github.com/WJQSERVER-STUDIO/httpc v0.7.0
github.com/fenthope/reco v0.0.3
github.com/go-json-experiment/json v0.0.0-20250517221953-25912455fbc8
)
require (
github.com/gorilla/schema v1.4.1 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
)