with one click
handlers-and-http
// Implement HTTP handlers that parse requests, invoke use cases, and format responses following REST conventions.
// Implement HTTP handlers that parse requests, invoke use cases, and format responses following REST conventions.
Write unit tests in Go following Red-Green-Refactor TDD principles.
Define and implement services that encapsulate business logic with proper constructor-based dependency injection.
Build pluggable authentication features using the plugin system with initialization, migrations, routes, and service registration.
Implement repository interfaces for data persistence and abstraction over database operations using Bun ORM.
Orchestrate services and repositories through use cases to implement application-level workflows and business scenarios.
Wire dependencies using constructor-based dependency injection throughout services, repositories, and handlers.
| name | handlers-and-http |
| description | Implement HTTP handlers that parse requests, invoke use cases, and format responses following REST conventions. |
constants/errors.go.Handlers are the HTTP boundary:
RegisterHandler needing both UserService and EmailService should delegate to a RegisterUseCase that imports both interfaces, keeping the handler thin and focused on HTTP concerns.Handle method with http.HandlerFunc type.Validate() method on request structs to clean up input but do not trim sensitive fields like passwords, tokens, etc. Before trimming fields on the request struct, check that pointer fields are not nil to avoid dereferencing nil pointers. For example, if you have a request struct with a pointer field like Email *string, you should check if Email is not nil before calling strings.TrimSpace() on it within the Validate() method. This ensures that you don't encounter a runtime panic due to dereferencing a nil pointer.reqCtx.SetJSONResponse.internal/ folder as there are utilities for request parsing, response formatting, and error handling. Avoid reinventing the wheel by utilising these utilities to ensure consistency across handlers.See examples/todo_handlers.go for:
reqCtx.SetJSONResponse for consistent response formatting or not using it to return the response at all, which can lead to inconsistent responses and missing status codes. Always use reqCtx.SetJSONResponse to ensure that responses are consistently formatted and include the appropriate status codes.