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 route options
Example:
module.Use[*User, *UserReq, *UserRsp](
&UserModule{},
module.CRUD(
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], options ...UseOption)
- func Wait()
- type UseOption
- type Wrapper
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Init ¶
func Init() error
Init releases pending module registrations.
Module registration runs asynchronously because module.Use can be called before the framework router and service registries are initialized. Init only opens that gate; callers that need registered models, services, or routes to be visible must call Wait after Init.
func NewWrapper ¶
func Use ¶
func Use[M types.Model, REQ types.Request, RSP types.Response](mod types.Module[M, REQ, RSP], options ...UseOption)
Use registers a module with the framework, automatically setting up model, service, and HTTP route registration for the specified route options.
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]
- options: Route options created by CRUD or Exact.
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 Wait ¶
func Wait()
Wait blocks until pending module.Use registrations are complete.
It waits for model, service, and route registration only. Database table creation and seed record insertion are handled separately by the database runtime. Callers that need module-provided tables and seed records to exist must call the database runtime drain after Wait, not before it, because module registration can enqueue new model.Register work.
Types ¶
type UseOption ¶
type UseOption struct {
// contains filtered or unexported fields
}
UseOption configures how module.Use registers routes for one or more phases.
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. |