Documentation
¶
Overview ¶
Package module provides a unified module registration system that automatically registers models, services, and HTTP routes for CRUD operations.
A module consists of three components:
- Model: Database entity implementing types.Model
- Service: Business logic implementing types.Service
- Module: Configuration implementing types.Module
Usage:
- Define model (embedding model.Base), request/response types, and service (embedding service.Base)
- Implement module with types.Module interface
- Call module.Use() with desired CRUD phases
Example:
module.Use[*User, *UserReq, *UserRsp](
&UserModule{},
consts.PHASE_CREATE,
consts.PHASE_LIST,
consts.PHASE_GET,
)
Route paths are normalized (leading slashes and "api/" prefix are removed). Authentication is controlled by Module.Pub() method.
See module/helloworld for complete examples.
Index ¶
- func Init() error
- func NewWrapper[M types.Model, REQ types.Request, RSP types.Response](route string, param string, pub bool, svc ...types.Service[M, REQ, RSP]) types.Module[M, REQ, RSP]
- func Use[M types.Model, REQ types.Request, RSP types.Response](mod types.Module[M, REQ, RSP], phases ...consts.Phase)
- func UseCustom[M types.Model, REQ types.Request, RSP types.Response](mod types.Module[M, REQ, RSP], phase consts.Phase)
- type Wrapper
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Init ¶ added in v0.10.1
func Init() error
Init notifies the module system that the framework is initialized. After calling Init, modules can start registering models, services, and routes.
func NewWrapper ¶ added in v0.10.5
func Use ¶
func Use[M types.Model, REQ types.Request, RSP types.Response](mod types.Module[M, REQ, RSP], phases ...consts.Phase)
Use registers a module with the framework, automatically setting up model, service, and HTTP route registration for the specified CRUD phases.
Type Parameters:
- M: Model type implementing types.Model
- REQ: Request type for API operations
- RSP: Response type for API operations
Parameters:
- mod: Module instance implementing types.Module[M, REQ, RSP]
- phases: CRUD phases to register. Available phases: PHASE_CREATE, PHASE_DELETE, PHASE_UPDATE, PHASE_PATCH, PHASE_LIST, PHASE_GET, PHASE_CREATE_MANY, PHASE_DELETE_MANY, PHASE_UPDATE_MANY, PHASE_PATCH_MANY
Routes are registered based on mod.Route() and mod.Param(). Authentication is determined by mod.Pub().
Must be called during application initialization, typically in a Register() function.
func UseCustom ¶ added in v0.10.14
func UseCustom[M types.Model, REQ types.Request, RSP types.Response](mod types.Module[M, REQ, RSP], phase consts.Phase)
UseCustom registers a service phase using the module route and the HTTP verb derived from the specified phase. It is intended for endpoints that reuse the module route but do not follow the default CRUD route registration pattern.
Types ¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package versionmod provides the version API module; the name avoids conflicting with the standard library "runtime/version" package.
|
Package versionmod provides the version API module; the name avoids conflicting with the standard library "runtime/version" package. |