Documentation
¶
Overview ¶
Package requestcore is the v2 module of requestCore.
v2 is a **generics-first**, framework-agnostic HTTP application toolkit that builds on the root github.com/hmmftg/requestCore module while preserving full backward compatibility. It requires **Go 1.27+** for generic methods on [handlers.Endpoint].
Core Features ¶
**Generic typed endpoints** — [handlers.Endpoint[Req, Resp]] flows request and response types through the entire lifecycle (parse, initialize, handle, render, finalize) without type erasure. Lifecycle hooks ([handlers.Endpoint.WithInitializer], [handlers.Endpoint.WithFinalizer], [handlers.Endpoint.WithPersistence]) are fully typed methods — no reflection, no runtime type-mismatch panics.
**Generic resources** — [resources.Resource[ID]] defines 7 CRUD operations where ID is constrained to cmp.Ordered (string, int, int64, etc.). The recommended path for v2 migration is [resources.Resource[ID]] paired with [resources.ResourceBuilder[ID]] for fluent registration. [resources.TypedResource] (14 type parameters) is an advanced alternative for cases requiring the strictest per-operation type guarantees — it is overkill for simple CRUD + custom resources.
**Typed session access** — [session.GetTyped[T]] and [session.SetTyped[T]] provide compile-time type-safe session value access. The [webFramework.SessionContext] and [webFramework.FlashContext] interfaces eliminate `any` type assertions in handlers.
**Generic response helpers** — [response.Handler.OKTyped[Resp]] and [response.Handler.OKWithStatusTyped[Resp]] render typed responses without `any` parameters.
**Framework-agnostic routing** — [routing.Router] and [routing.RouteGroup] interfaces work across Gin, Fiber, chi, and net/http via adapter packages ([libGin], [libFiber], [libChi], [libNetHttp]).
**Pluggable renderers** — renderers.Renderer interface with built-in JSON, XML, text, and CSV renderers.
**Error handler registry** — response.Registry with per-status handlers and legacy fallback.
**Bounded worker pool** — workers.InProcessWorker with retry, tracing, and mandatory [webFramework.AddLog] observability.
**Scheduler** — workers.Scheduler for periodic background tasks.
**CLI code generators** — `requestcore` CLI generates handlers, resources, middleware, and project scaffolding.
Module Structure ¶
The v2 module lives in the v2/ directory and imports the root module for delegation to existing query, persistence, response, logging, and tracing infrastructure. The root module never imports v2.
See MIGRATION.md for the v1-to-v2 migration guide and README.md for the v2 module overview.
Index ¶
- type Model
- func (m *Model) DefaultRenderer() renderers.Renderer
- func (m *Model) ErrorHandlers() v2response.Registry
- func (m *Model) GetDB() libQuery.QueryRunnerInterface
- func (m *Model) Legacy() requestCore.RequestCoreInterface
- func (m *Model) ORM() liborm.OrmInterface
- func (m *Model) Params() libParams.ParamInterface
- func (m *Model) RequestTools() libRequest.RequestInterface
- func (m *Model) Responder() response.ResponseHandler
- func (m *Model) SessionManager() *session.Manager
- func (m *Model) V2Responder() *v2response.Handler
- func (m *Model) WorkerPool() workers.Worker
- type Runtime
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Model ¶
type Model struct {
LegacyCore requestCore.RequestCoreInterface
ResponseHandler *v2response.Handler
Errors v2response.Registry
Renderer renderers.Renderer
Worker workers.Worker
Sessions *session.Manager
}
Model is the default Runtime implementation. It composes the v1 RequestCoreInterface with v2 features.
func NewModel ¶
func NewModel( legacyCore requestCore.RequestCoreInterface, legacyHandler response.WebHanlder, renderer renderers.Renderer, worker workers.Worker, sessionStore session.Store, ) *Model
NewModel creates a v2 Model from the given v1 core and v2 feature components. If any v2 component is nil, safe defaults are used.
func (*Model) DefaultRenderer ¶
DefaultRenderer returns the default renderer.
func (*Model) ErrorHandlers ¶
func (m *Model) ErrorHandlers() v2response.Registry
ErrorHandlers returns the error handler registry.
func (*Model) GetDB ¶
func (m *Model) GetDB() libQuery.QueryRunnerInterface
GetDB delegates to the v1 core.
func (*Model) Legacy ¶
func (m *Model) Legacy() requestCore.RequestCoreInterface
Legacy returns the v1 RequestCoreInterface.
func (*Model) Params ¶
func (m *Model) Params() libParams.ParamInterface
Params delegates to the v1 core.
func (*Model) RequestTools ¶
func (m *Model) RequestTools() libRequest.RequestInterface
RequestTools delegates to the v1 core.
func (*Model) Responder ¶
func (m *Model) Responder() response.ResponseHandler
Responder returns the v1 response handler, implementing RequestCoreInterface.
func (*Model) SessionManager ¶
SessionManager returns the session manager.
func (*Model) V2Responder ¶
func (m *Model) V2Responder() *v2response.Handler
V2Responder returns the v2 response handler.
func (*Model) WorkerPool ¶
WorkerPool returns the worker pool.
type Runtime ¶
type Runtime interface {
// Legacy returns the v1 RequestCoreInterface for access to existing
// query, persistence, response, logging, and tracing infrastructure.
Legacy() requestCore.RequestCoreInterface
// V2Responder returns the v2 response handler with renderer support
// and error handler registry. Named V2Responder to avoid conflict
// with the v1 RequestCoreInterface.Responder method.
V2Responder() *v2response.Handler
// ErrorHandlers returns the error handler registry.
ErrorHandlers() v2response.Registry
// DefaultRenderer returns the default renderer (JSON by default).
DefaultRenderer() renderers.Renderer
// WorkerPool returns the in-process worker pool.
WorkerPool() workers.Worker
// SessionManager returns the session manager.
SessionManager() *session.Manager
// GetDB returns the query runner interface (delegates to v1).
GetDB() libQuery.QueryRunnerInterface
// ORM returns the ORM interface (delegates to v1).
ORM() liborm.OrmInterface
// RequestTools returns the request interface (delegates to v1).
RequestTools() libRequest.RequestInterface
// Responder returns the v1 response handler (delegates to v1).
// This matches the v1 RequestCoreInterface.Responder signature.
Responder() response.ResponseHandler
// Params returns the parameter interface (delegates to v1).
Params() libParams.ParamInterface
}
Runtime is the v2 runtime façade providing access to all v2 features while delegating to the v1 RequestCoreInterface for existing infrastructure.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package app provides a framework-neutral application bootstrap for v2 requestCore applications.
|
Package app provides a framework-neutral application bootstrap for v2 requestCore applications. |
|
cmd
|
|
|
requestcore
Package cmd provides the requestcore CLI for generating v2 application scaffolding, including handlers, resources, middleware, and project structure.
|
Package cmd provides the requestcore CLI for generating v2 application scaffolding, including handlers, resources, middleware, and project structure. |
|
requestcore/cmd
command
|
|
|
examples
|
|
|
simple
command
Package main is a v2 requestCore example application using chi.
|
Package main is a v2 requestCore example application using chi. |
|
Package handlers provides the v2 request handler lifecycle, typed endpoint descriptors, and resource primitives for requestCore applications.
|
Package handlers provides the v2 request handler lifecycle, typed endpoint descriptors, and resource primitives for requestCore applications. |
|
Package libChi provides the v2 chi web framework adapter for requestCore.
|
Package libChi provides the v2 chi web framework adapter for requestCore. |
|
Package libFiber provides the v2 Fiber web framework adapter for requestCore.
|
Package libFiber provides the v2 Fiber web framework adapter for requestCore. |
|
Package libGin provides the v2 Gin web framework adapter for requestCore.
|
Package libGin provides the v2 Gin web framework adapter for requestCore. |
|
Package libNetHttp provides the v2 net/http web framework adapter for requestCore.
|
Package libNetHttp provides the v2 net/http web framework adapter for requestCore. |
|
Package renderers provides pluggable content renderers for v2 response handling.
|
Package renderers provides pluggable content renderers for v2 response handling. |
|
Package resources provides v2 resource registration with seven standard CRUD operations, inspired by Buffalo's resource pattern.
|
Package resources provides v2 resource registration with seven standard CRUD operations, inspired by Buffalo's resource pattern. |
|
Package response provides the v2 response handler with a centralized error handler registry and pluggable renderers.
|
Package response provides the v2 response handler with a centralized error handler registry and pluggable renderers. |
|
Package routing provides framework-agnostic route groups, middleware, and a Router interface implemented by Gin, Fiber, and net/http+chi adapters.
|
Package routing provides framework-agnostic route groups, middleware, and a Router interface implemented by Gin, Fiber, and net/http+chi adapters. |
|
Package session provides pluggable session and flash management for v2.
|
Package session provides pluggable session and flash management for v2. |
|
Package testingtools provides test utilities for v2 handler and middleware testing, including a test parser, test router, and initialization helpers.
|
Package testingtools provides test utilities for v2 handler and middleware testing, including a test parser, test router, and initialization helpers. |
|
Package webFramework provides the v2 web framework abstraction layer.
|
Package webFramework provides the v2 web framework abstraction layer. |
|
Package workers provides a bounded in-process worker pool with retry, tracing, and mandatory observability through webFramework.AddLog.
|
Package workers provides a bounded in-process worker pool with retry, tracing, and mandatory observability through webFramework.AddLog. |