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, *UserService](
&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 ¶
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, S types.Service[M, REQ, RSP]](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
- S: Service type implementing types.Service[M, REQ, RSP]
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.